2020-02-02 17:04:16 +00:00
|
|
|
module AvailabilityStatusable
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2020-07-04 06:12:47 +00:00
|
|
|
def online_presence?
|
2021-10-07 07:51:46 +00:00
|
|
|
obj_id = is_a?(Contact) ? id : user_id
|
|
|
|
::OnlineStatusTracker.get_presence(account_id, self.class.name, obj_id)
|
2020-02-02 17:04:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def availability_status
|
2021-10-07 07:51:46 +00:00
|
|
|
if is_a? Contact
|
|
|
|
contact_availability_status
|
|
|
|
else
|
|
|
|
user_availability_status
|
|
|
|
end
|
2020-07-04 06:12:47 +00:00
|
|
|
end
|
|
|
|
|
2021-10-07 07:51:46 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def contact_availability_status
|
|
|
|
online_presence? ? 'online' : 'offline'
|
2020-07-04 14:33:16 +00:00
|
|
|
end
|
|
|
|
|
2021-10-07 07:51:46 +00:00
|
|
|
def user_availability_status
|
|
|
|
# we are not considering presence in this case. Just returns the availability
|
|
|
|
return availability unless auto_offline
|
2020-07-04 06:12:47 +00:00
|
|
|
|
2021-10-07 07:51:46 +00:00
|
|
|
# availability as a fallback in case the status is not present in redis
|
|
|
|
online_presence? ? (::OnlineStatusTracker.get_status(account_id, user_id) || availability) : 'offline'
|
2020-02-02 17:04:16 +00:00
|
|
|
end
|
|
|
|
end
|