Chore: Fix presence for current user (#1001)

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose
2020-07-04 20:03:16 +05:30
committed by GitHub
parent 4612494923
commit 43147b3163
11 changed files with 78 additions and 20 deletions

View File

@@ -2,19 +2,29 @@ module AvailabilityStatusable
extend ActiveSupport::Concern
def online_presence?
return if user_profile_page_context?
::OnlineStatusTracker.get_presence(availability_account_id, self.class.name, id)
end
def availability_status
return availability if user_profile_page_context?
return 'offline' unless online_presence?
return 'online' if is_a? Contact
::OnlineStatusTracker.get_status(availability_account_id, id) || 'online'
end
def user_profile_page_context?
# at the moment profile pages aren't account scoped
# hence we will return availability attribute instead of true presence
# we will revisit this later
is_a?(User) && Current.account.blank?
end
def availability_account_id
return account_id if is_a? Contact
Current.account.present? ? Current.account.id : accounts.first.id
Current.account.id
end
end