From 0b31e141329b319f00b52cbc8b6c12867a514f53 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Sun, 2 Feb 2020 22:34:16 +0530 Subject: [PATCH] Feature: Add online status to each user (#452) * Feature: Add online status to each user * Add OnlineStatusable, add availability status to thumbnail --- app/channels/room_channel.rb | 5 ++++ app/controllers/api/v1/agents_controller.rb | 2 +- .../components/widgets/Thumbnail.vue | 30 +++++++++++++++++-- .../dashboard/conversation/ContactPanel.vue | 1 + .../dashboard/settings/agents/Index.vue | 3 +- .../widget/store/modules/conversation.js | 10 +++---- .../specs/conversation/getters.spec.js | 23 ++++++++++++-- .../concerns/availability_statusable.rb | 11 +++++++ app/models/contact.rb | 1 + app/models/user.rb | 1 + app/views/api/v1/agents/index.json.jbuilder | 10 +++++++ app/views/api/v1/contacts/show.json.jbuilder | 3 +- .../widget/inbox_members/index.json.jbuilder | 1 + lib/online_status_tracker.rb | 19 ++++++++++++ 14 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 app/models/concerns/availability_statusable.rb create mode 100644 app/views/api/v1/agents/index.json.jbuilder create mode 100644 lib/online_status_tracker.rb diff --git a/app/channels/room_channel.rb b/app/channels/room_channel.rb index c04b72877..df1a05d6b 100644 --- a/app/channels/room_channel.rb +++ b/app/channels/room_channel.rb @@ -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 diff --git a/app/controllers/api/v1/agents_controller.rb b/app/controllers/api/v1/agents_controller.rb index 681422515..a1758b40b 100644 --- a/app/controllers/api/v1/agents_controller.rb +++ b/app/controllers/api/v1/agents_controller.rb @@ -4,7 +4,7 @@ class Api::V1::AgentsController < Api::BaseController before_action :build_agent, only: [:create] def index - render json: agents + @agents = agents end def destroy diff --git a/app/javascript/dashboard/components/widgets/Thumbnail.vue b/app/javascript/dashboard/components/widgets/Thumbnail.vue index d2a0a50b2..b27a49028 100644 --- a/app/javascript/dashboard/components/widgets/Thumbnail.vue +++ b/app/javascript/dashboard/components/widgets/Thumbnail.vue @@ -16,12 +16,17 @@ :size="avatarSize" /> +