fix: Add an action cable events for label updates (#5694)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
parent
782165478b
commit
4a299a9441
6 changed files with 41 additions and 2 deletions
|
@ -252,6 +252,12 @@ const actions = {
|
|||
meta: { sender },
|
||||
} = conversation;
|
||||
commit(types.UPDATE_CONVERSATION, conversation);
|
||||
|
||||
dispatch('conversationLabels/setConversationLabel', {
|
||||
id: conversation.id,
|
||||
data: conversation.labels,
|
||||
});
|
||||
|
||||
dispatch('contacts/setContact', sender);
|
||||
},
|
||||
|
||||
|
|
|
@ -262,6 +262,8 @@ class Conversation < ApplicationRecord
|
|||
previous_labels, current_labels = previous_changes[:label_list]
|
||||
return unless (previous_labels.is_a? Array) && (current_labels.is_a? Array)
|
||||
|
||||
dispatcher_dispatch(CONVERSATION_UPDATED, previous_changes)
|
||||
|
||||
create_label_added(user_name, current_labels - previous_labels)
|
||||
create_label_removed(user_name, previous_labels - current_labels)
|
||||
end
|
||||
|
|
|
@ -8,6 +8,7 @@ class Conversations::EventDataPresenter < SimpleDelegator
|
|||
id: display_id,
|
||||
inbox_id: inbox_id,
|
||||
messages: push_messages,
|
||||
labels: label_list,
|
||||
meta: push_meta,
|
||||
status: status,
|
||||
custom_attributes: custom_attributes,
|
||||
|
|
|
@ -133,6 +133,10 @@ describe ActionCableListener do
|
|||
let(:event_name) { :'conversation.updated' }
|
||||
let!(:event) { Events::Base.new(event_name, Time.zone.now, conversation: conversation, user: agent, is_private: false) }
|
||||
|
||||
before do
|
||||
conversation.add_labels(['support'])
|
||||
end
|
||||
|
||||
it 'sends update to inbox members' do
|
||||
expect(conversation.inbox.reload.inbox_members.count).to eq(1)
|
||||
|
||||
|
@ -143,5 +147,16 @@ describe ActionCableListener do
|
|||
)
|
||||
listener.conversation_updated(event)
|
||||
end
|
||||
|
||||
it 'broadcast event with label data' do
|
||||
expect(conversation.push_event_data[:labels]).to eq(conversation.label_list)
|
||||
|
||||
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
|
||||
|
|
|
@ -109,12 +109,25 @@ RSpec.describe Conversation, type: :model do
|
|||
Current.user = old_assignee
|
||||
end
|
||||
|
||||
it 'sends conversation updated event if labels are updated' do
|
||||
conversation.update(label_list: [label.title])
|
||||
changed_attributes = conversation.previous_changes
|
||||
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
|
||||
.with(
|
||||
described_class::CONVERSATION_UPDATED,
|
||||
kind_of(Time),
|
||||
conversation: conversation,
|
||||
notifiable_assignee_change: false,
|
||||
changed_attributes: changed_attributes,
|
||||
performed_by: nil
|
||||
)
|
||||
end
|
||||
|
||||
it 'runs after_update callbacks' do
|
||||
conversation.update(
|
||||
status: :resolved,
|
||||
contact_last_seen_at: Time.now,
|
||||
assignee: new_assignee,
|
||||
label_list: [label.title]
|
||||
assignee: new_assignee
|
||||
)
|
||||
status_change = conversation.status_change
|
||||
changed_attributes = conversation.previous_changes
|
||||
|
@ -433,6 +446,7 @@ RSpec.describe Conversation, type: :model do
|
|||
},
|
||||
id: conversation.display_id,
|
||||
messages: [],
|
||||
labels: [],
|
||||
inbox_id: conversation.inbox_id,
|
||||
status: conversation.status,
|
||||
contact_inbox: conversation.contact_inbox,
|
||||
|
|
|
@ -19,6 +19,7 @@ RSpec.describe Conversations::EventDataPresenter do
|
|||
id: conversation.display_id,
|
||||
messages: [],
|
||||
inbox_id: conversation.inbox_id,
|
||||
labels: [],
|
||||
status: conversation.status,
|
||||
contact_inbox: conversation.contact_inbox,
|
||||
can_reply: conversation.can_reply?,
|
||||
|
|
Loading…
Reference in a new issue