diff --git a/app/listeners/notification_listener.rb b/app/listeners/notification_listener.rb index bfa2ec99f..ad7bf2d14 100644 --- a/app/listeners/notification_listener.rb +++ b/app/listeners/notification_listener.rb @@ -56,6 +56,8 @@ class NotificationListener < BaseListener def generate_notifications_for_mentions(message, account) return unless message.private? + return if message.content.blank? + mentioned_ids = message.content.scan(%r{\(mention://(user|team)/(\d+)/(.+)\)}).map(&:second).uniq return if mentioned_ids.blank? diff --git a/spec/listeners/notification_listener_spec.rb b/spec/listeners/notification_listener_spec.rb index 8a80cd82f..4cbf3243d 100644 --- a/spec/listeners/notification_listener_spec.rb +++ b/spec/listeners/notification_listener_spec.rb @@ -47,13 +47,15 @@ describe NotificationListener do describe 'message_created' do let(:event_name) { :'message.created' } + before do + notification_setting = agent_with_notification.notification_settings.find_by(account_id: account.id) + notification_setting.selected_email_flags = [:email_conversation_mention] + notification_setting.selected_push_flags = [] + notification_setting.save! + end + context 'when message contains mention' do it 'creates notifications for inbox member who was mentioned' do - notification_setting = agent_with_notification.notification_settings.find_by(account_id: account.id) - notification_setting.selected_email_flags = [:email_conversation_mention] - notification_setting.selected_push_flags = [] - notification_setting.save! - builder = double allow(NotificationBuilder).to receive(:new).and_return(builder) allow(builder).to receive(:perform) @@ -78,5 +80,28 @@ describe NotificationListener do primary_actor: message) end end + + context 'when message content is empty' do + it 'creates notifications' do + builder = double + allow(NotificationBuilder).to receive(:new).and_return(builder) + allow(builder).to receive(:perform) + + create(:inbox_member, user: agent_with_notification, inbox: inbox) + conversation.reload + + message = build( + :message, + conversation: conversation, + account: account, + content: nil, + private: true + ) + + event = Events::Base.new(event_name, Time.zone.now, message: message) + # want to validate message_created doesnt throw an error + expect(listener.message_created(event)).to eq nil + end + end end end