Chatwoot/lib/online_status_tracker.rb
Pranav Raj S 0b31e14132
Feature: Add online status to each user (#452)
* Feature: Add online status to each user
* Add OnlineStatusable, add availability status to thumbnail
2020-02-02 22:49:16 +05:45

19 lines
491 B
Ruby

module OnlineStatusTracker
def self.add_subscription(channel_id)
count = subscription_count(channel_id)
::Redis::Alfred.setex(channel_id, count + 1)
end
def self.remove_subscription(channel_id)
count = subscription_count(channel_id)
if count == 1
::Redis::Alfred.delete(channel_id)
elsif count != 0
::Redis::Alfred.setex(channel_id, count - 1)
end
end
def self.subscription_count(channel_id)
::Redis::Alfred.get(channel_id).to_i
end
end