fix: Skip notifications for private notes (#13617)
When agents or integrations create private notes on a conversation, every note was sending a notification to the assigned agent and all conversation participants. The fix ensures that private notes no longer trigger new message notifications. If someone explicitly mentions a teammate in a private note, that person will still get notified as expected.
This commit is contained in:
@@ -14,7 +14,7 @@ module MessageFilterHelpers
|
||||
end
|
||||
|
||||
def notifiable?
|
||||
incoming? || outgoing?
|
||||
(incoming? || outgoing?) && !private?
|
||||
end
|
||||
|
||||
def conversation_transcriptable?
|
||||
|
||||
@@ -142,7 +142,24 @@ describe NotificationListener do
|
||||
expect(first_agent.notifications.first.notification_type).to eq('conversation_mention')
|
||||
end
|
||||
|
||||
it 'will not create duplicate new message notifications for assignment & participation' do
|
||||
it 'will create a mention notification when a user is mentioned in a private note' do
|
||||
create(:inbox_member, user: first_agent, inbox: inbox)
|
||||
|
||||
message = build(
|
||||
:message,
|
||||
conversation: conversation,
|
||||
account: account,
|
||||
content: "hey [#{first_agent.name}](mention://user/#{first_agent.id}/#{first_agent.name})",
|
||||
private: true
|
||||
)
|
||||
event = Events::Base.new(event_name, Time.zone.now, message: message)
|
||||
listener.message_created(event)
|
||||
|
||||
expect(first_agent.notifications.count).to eq(1)
|
||||
expect(first_agent.notifications.first.notification_type).to eq('conversation_mention')
|
||||
end
|
||||
|
||||
it 'will not create new message notifications for private messages without mentions' do
|
||||
create(:inbox_member, user: first_agent, inbox: inbox)
|
||||
conversation.update(assignee: first_agent)
|
||||
# participants is created by async job. so creating it directly for testcase
|
||||
@@ -160,8 +177,7 @@ describe NotificationListener do
|
||||
listener.message_created(event)
|
||||
|
||||
expect(conversation.conversation_participants.map(&:user)).to include(first_agent)
|
||||
expect(first_agent.notifications.count).to eq(1)
|
||||
expect(first_agent.notifications.first.notification_type).to eq('assigned_conversation_new_message')
|
||||
expect(first_agent.notifications.count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,11 +2,17 @@ require 'rails_helper'
|
||||
|
||||
describe Messages::NewMessageNotificationService do
|
||||
context 'when message is not notifiable' do
|
||||
it 'will not create any notifications' do
|
||||
it 'will not create any notifications for activity messages' do
|
||||
message = build(:message, message_type: :activity)
|
||||
expect(NotificationBuilder).not_to receive(:new)
|
||||
described_class.new(message: message).perform
|
||||
end
|
||||
|
||||
it 'will not create any notifications for private messages' do
|
||||
message = build(:message, message_type: :outgoing, private: true)
|
||||
expect(NotificationBuilder).not_to receive(:new)
|
||||
described_class.new(message: message).perform
|
||||
end
|
||||
end
|
||||
|
||||
context 'when message is notifiable' do
|
||||
|
||||
Reference in New Issue
Block a user