forked from chatwoot/chatwoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add online status to each user (chatwoot#452)
* Feature: Add online status to each user * Add OnlineStatusable, add availability status to thumbnail
- Loading branch information
1 parent
1f4703d
commit 0b31e14
Showing
14 changed files
with
106 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
class RoomChannel < ApplicationCable::Channel | ||
def subscribed | ||
stream_from params[:pubsub_token] | ||
::OnlineStatusTracker.add_subscription(params[:pubsub_token]) | ||
end | ||
|
||
def unsubscribed | ||
::OnlineStatusTracker.remove_subscription(params[:pubsub_token]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module AvailabilityStatusable | ||
extend ActiveSupport::Concern | ||
|
||
def online? | ||
::OnlineStatusTracker.subscription_count(pubsub_token) != 0 | ||
end | ||
|
||
def availability_status | ||
online? ? 'online' : 'offline' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
json.array! @agents do |agent| | ||
json.account_id agent.account_id | ||
json.availability_status agent.availability_status | ||
json.confirmed agent.confirmed? | ||
json.email agent.email | ||
json.id agent.id | ||
json.name agent.name | ||
json.role agent.role | ||
json.thumbnail agent.avatar_url | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
json.payload do | ||
json.availability_status @contact.availability_status | ||
json.email @contact.email | ||
json.id @contact.id | ||
json.name @contact.name | ||
json.email @contact.email | ||
json.phone_number @contact.phone_number | ||
json.thumbnail @contact.avatar_url | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |