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