Chore: Fix presence for current user (#1001)

Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose
2020-07-04 20:03:16 +05:30
committed by GitHub
parent 4612494923
commit 43147b3163
11 changed files with 78 additions and 20 deletions

View File

@@ -4,17 +4,22 @@ class RoomChannel < ApplicationCable::Channel
current_user
current_account
update_subscription
broadcast_presence
end
def update_presence
update_subscription
broadcast_presence
end
private
def broadcast_presence
data = { account_id: @current_account.id, users: ::OnlineStatusTracker.get_available_users(@current_account.id) }
data[:contacts] = ::OnlineStatusTracker.get_available_contacts(@current_account.id) if @current_user.is_a? User
ActionCable.server.broadcast(@pubsub_token, { event: 'presence.update', data: data })
end
private
def ensure_stream
@pubsub_token = params[:pubsub_token]
stream_from @pubsub_token