Feature: Add online status to each user (#452)
* Feature: Add online status to each user * Add OnlineStatusable, add availability status to thumbnail
This commit is contained in:
19
lib/online_status_tracker.rb
Normal file
19
lib/online_status_tracker.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
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
|
||||
Reference in New Issue
Block a user