2020-02-02 17:04:16 +00:00
|
|
|
module AvailabilityStatusable
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2020-07-04 06:12:47 +00:00
|
|
|
def online_presence?
|
2020-07-04 14:33:16 +00:00
|
|
|
return if user_profile_page_context?
|
|
|
|
|
2020-07-04 06:12:47 +00:00
|
|
|
::OnlineStatusTracker.get_presence(availability_account_id, self.class.name, id)
|
2020-02-02 17:04:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def availability_status
|
2020-07-04 14:33:16 +00:00
|
|
|
return availability if user_profile_page_context?
|
2020-07-04 06:12:47 +00:00
|
|
|
return 'offline' unless online_presence?
|
|
|
|
return 'online' if is_a? Contact
|
|
|
|
|
|
|
|
::OnlineStatusTracker.get_status(availability_account_id, id) || 'online'
|
|
|
|
end
|
|
|
|
|
2020-07-04 14:33:16 +00:00
|
|
|
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
|
|
|
|
|
2020-07-04 06:12:47 +00:00
|
|
|
def availability_account_id
|
|
|
|
return account_id if is_a? Contact
|
|
|
|
|
2020-07-04 14:33:16 +00:00
|
|
|
Current.account.id
|
2020-02-02 17:04:16 +00:00
|
|
|
end
|
|
|
|
end
|