diff --git a/app/models/concerns/message_filter_helpers.rb b/app/models/concerns/message_filter_helpers.rb index 38124f347..39ee71089 100644 --- a/app/models/concerns/message_filter_helpers.rb +++ b/app/models/concerns/message_filter_helpers.rb @@ -14,7 +14,7 @@ module MessageFilterHelpers end def notifiable? - incoming? || outgoing? + (incoming? || outgoing?) && !private? end def conversation_transcriptable? diff --git a/spec/listeners/notification_listener_spec.rb b/spec/listeners/notification_listener_spec.rb index 76e458b8e..048339ca5 100644 --- a/spec/listeners/notification_listener_spec.rb +++ b/spec/listeners/notification_listener_spec.rb @@ -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 diff --git a/spec/services/messages/new_message_notification_service_spec.rb b/spec/services/messages/new_message_notification_service_spec.rb index 51da1ad5a..c8e2b7b98 100644 --- a/spec/services/messages/new_message_notification_service_spec.rb +++ b/spec/services/messages/new_message_notification_service_spec.rb @@ -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