chore: Move agent availability to Account level (#3074)

- Move agent availability to the account level
This commit is contained in:
Sojan Jose
2021-10-07 13:21:46 +05:30
committed by GitHub
parent 1c6a539c0a
commit c54aae21ff
84 changed files with 618 additions and 148 deletions

View File

@@ -2,29 +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)
obj_id = is_a?(Contact) ? id : user_id
::OnlineStatusTracker.get_presence(account_id, self.class.name, obj_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'
if is_a? Contact
contact_availability_status
else
user_availability_status
end
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?
private
def contact_availability_status
online_presence? ? 'online' : 'offline'
end
def availability_account_id
return account_id if is_a? Contact
def user_availability_status
# we are not considering presence in this case. Just returns the availability
return availability unless auto_offline
Current.account.id
# availability as a fallback in case the status is not present in redis
online_presence? ? (::OnlineStatusTracker.get_status(account_id, user_id) || availability) : 'offline'
end
end