feat: Update conversation attributes in realtime when they changed (#5542)
Co-authored-by: daniel gannage <daniel@pxdel.com> Co-authored-by: Tejaswini Chile <tejaswini@chatwoot.com>
This commit is contained in:
parent
10d86fbb35
commit
a3277b45af
3 changed files with 29 additions and 0 deletions
|
@ -25,6 +25,7 @@ class ActionCableConnector extends BaseActionCableConnector {
|
||||||
'notification.created': this.onNotificationCreated,
|
'notification.created': this.onNotificationCreated,
|
||||||
'first.reply.created': this.onFirstReplyCreated,
|
'first.reply.created': this.onFirstReplyCreated,
|
||||||
'conversation.read': this.onConversationRead,
|
'conversation.read': this.onConversationRead,
|
||||||
|
'conversation.updated': this.onConversationUpdated,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +86,11 @@ class ActionCableConnector extends BaseActionCableConnector {
|
||||||
this.fetchConversationStats();
|
this.fetchConversationStats();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onConversationUpdated = data => {
|
||||||
|
this.app.$store.dispatch('updateConversation', data);
|
||||||
|
this.fetchConversationStats();
|
||||||
|
};
|
||||||
|
|
||||||
onTypingOn = ({ conversation, user }) => {
|
onTypingOn = ({ conversation, user }) => {
|
||||||
const conversationId = conversation.id;
|
const conversationId = conversation.id;
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,13 @@ class ActionCableListener < BaseListener
|
||||||
broadcast(account, tokens, CONVERSATION_STATUS_CHANGED, conversation.push_event_data)
|
broadcast(account, tokens, CONVERSATION_STATUS_CHANGED, conversation.push_event_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def conversation_updated(event)
|
||||||
|
conversation, account = extract_conversation_and_account(event)
|
||||||
|
tokens = user_tokens(account, conversation.inbox.members) + contact_inbox_tokens(conversation.contact_inbox)
|
||||||
|
|
||||||
|
broadcast(account, tokens, CONVERSATION_UPDATED, conversation.push_event_data)
|
||||||
|
end
|
||||||
|
|
||||||
def conversation_typing_on(event)
|
def conversation_typing_on(event)
|
||||||
conversation = event.data[:conversation]
|
conversation = event.data[:conversation]
|
||||||
account = conversation.account
|
account = conversation.account
|
||||||
|
|
|
@ -128,4 +128,20 @@ describe ActionCableListener do
|
||||||
listener.contact_deleted(event)
|
listener.contact_deleted(event)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#conversation_updated' do
|
||||||
|
let(:event_name) { :'conversation.updated' }
|
||||||
|
let!(:event) { Events::Base.new(event_name, Time.zone.now, conversation: conversation, user: agent, is_private: false) }
|
||||||
|
|
||||||
|
it 'sends update to inbox members' do
|
||||||
|
expect(conversation.inbox.reload.inbox_members.count).to eq(1)
|
||||||
|
|
||||||
|
expect(ActionCableBroadcastJob).to receive(:perform_later).with(
|
||||||
|
[agent.pubsub_token, admin.pubsub_token, conversation.contact_inbox.pubsub_token],
|
||||||
|
'conversation.updated',
|
||||||
|
conversation.push_event_data.merge(account_id: account.id)
|
||||||
|
)
|
||||||
|
listener.conversation_updated(event)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue