Feature: Api to toggle typing status on a conversation (#807)
- api to toggle typing status on a conversation - clients receive webhook events on the same Addresses: #718 , #719 , #775
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
class Api::V1::Accounts::ConversationsController < Api::BaseController
|
||||
include Events::Types
|
||||
before_action :conversation, except: [:index]
|
||||
before_action :contact_inbox, only: [:create]
|
||||
|
||||
@@ -23,6 +24,16 @@ class Api::V1::Accounts::ConversationsController < Api::BaseController
|
||||
@status = @conversation.toggle_status
|
||||
end
|
||||
|
||||
def toggle_typing_status
|
||||
user = current_user.presence || @resource
|
||||
if params[:typing_status] == 'on'
|
||||
Rails.configuration.dispatcher.dispatch(CONVERSATION_TYPING_ON, Time.zone.now, conversation: @conversation, user: user)
|
||||
elsif params[:typing_status] == 'off'
|
||||
Rails.configuration.dispatcher.dispatch(CONVERSATION_TYPING_OFF, Time.zone.now, conversation: @conversation)
|
||||
end
|
||||
head :ok
|
||||
end
|
||||
|
||||
def update_last_seen
|
||||
@conversation.agent_last_seen_at = parsed_last_seen_at
|
||||
@conversation.save!
|
||||
|
||||
@@ -48,6 +48,28 @@ class ActionCableListener < BaseListener
|
||||
broadcast(user_tokens(account, conversation.inbox.members), CONVERSATION_LOCK_TOGGLE, conversation.lock_event_data)
|
||||
end
|
||||
|
||||
def conversation_typing_on(event)
|
||||
conversation = event.data[:conversation]
|
||||
account = conversation.account
|
||||
user = event.data[:user]
|
||||
tokens = user_tokens(account, conversation.inbox.members) +
|
||||
[conversation.contact.pubsub_token]
|
||||
|
||||
broadcast(tokens, CONVERSATION_TYPING_ON,
|
||||
conversation: conversation.push_event_data, user: user.push_event_data)
|
||||
end
|
||||
|
||||
def conversation_typing_off(event)
|
||||
conversation = event.data[:conversation]
|
||||
account = conversation.account
|
||||
user = event.data[:user]
|
||||
tokens = user_tokens(account, conversation.inbox.members) +
|
||||
[conversation.contact.pubsub_token]
|
||||
|
||||
broadcast(tokens, CONVERSATION_TYPING_OFF,
|
||||
conversation: conversation.push_event_data, user: user.push_event_data)
|
||||
end
|
||||
|
||||
def assignee_changed(event)
|
||||
conversation, account, timestamp = extract_conversation_and_account(event)
|
||||
|
||||
|
||||
@@ -16,4 +16,20 @@ class AgentBot < ApplicationRecord
|
||||
|
||||
has_many :agent_bot_inboxes, dependent: :destroy
|
||||
has_many :inboxes, through: :agent_bot_inboxes
|
||||
|
||||
def push_event_data
|
||||
{
|
||||
name: name,
|
||||
avatar_url: avatar_url,
|
||||
type: 'agent_bot'
|
||||
}
|
||||
end
|
||||
|
||||
def webhook_data
|
||||
{
|
||||
id: id,
|
||||
name: name,
|
||||
type: 'agent_bot'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,6 +50,7 @@ class Contact < ApplicationRecord
|
||||
id: id,
|
||||
name: name,
|
||||
thumbnail: avatar_url,
|
||||
type: 'contact',
|
||||
pubsub_token: pubsub_token
|
||||
}
|
||||
end
|
||||
@@ -58,7 +59,8 @@ class Contact < ApplicationRecord
|
||||
{
|
||||
id: id,
|
||||
name: name,
|
||||
avatar: avatar_url
|
||||
avatar: avatar_url,
|
||||
type: 'contact'
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -129,7 +129,8 @@ class User < ApplicationRecord
|
||||
def push_event_data
|
||||
{
|
||||
name: name,
|
||||
avatar_url: avatar_url
|
||||
avatar_url: avatar_url,
|
||||
type: 'user'
|
||||
}
|
||||
end
|
||||
|
||||
@@ -137,7 +138,8 @@ class User < ApplicationRecord
|
||||
{
|
||||
id: id,
|
||||
name: name,
|
||||
email: email
|
||||
email: email,
|
||||
type: 'user'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user