From 146775072a1183b6d1a2a6be33a83e7480d8bede Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Wed, 17 Mar 2021 08:20:41 +1100 Subject: [PATCH] FIX: mention notification takes precedence over group (#12407) When a specific user is mentioned and group to which this user belongs, a direct mention notification should take precedence. --- app/services/post_alerter.rb | 10 +++++----- spec/services/post_alerter_spec.rb | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index eb5f5bbf384..fc6c74bed88 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -70,15 +70,15 @@ class PostAlerter mentioned_opts = { user_id: editor.id, original_username: editor.username, display_username: editor.username } end - expand_group_mentions(mentioned_groups, post) do |group, users| - users = only_allowed_users(users, post) - notified += notify_users(users - notified, :group_mentioned, post, mentioned_opts.merge(group: group)) - end - if mentioned_users mentioned_users = only_allowed_users(mentioned_users, post) notified += notify_users(mentioned_users - notified, :mentioned, post, mentioned_opts) end + + expand_group_mentions(mentioned_groups, post) do |group, users| + users = only_allowed_users(users, post) + notified += notify_users(users - notified, :group_mentioned, post, mentioned_opts.merge(group: group)) + end end # replies diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rb index c70d47815f0..8d492c14b73 100644 --- a/spec/services/post_alerter_spec.rb +++ b/spec/services/post_alerter_spec.rb @@ -380,6 +380,13 @@ describe PostAlerter do expect(GroupMention.count).to eq(4) end + it 'takes private mention as precedence' do + expect { + create_post_with_alerts(raw: "Hello @group and @eviltrout, nice to meet you") + }.to change(evil_trout.notifications, :count).by(1) + expect(evil_trout.notifications.last.notification_type).to eq(Notification.types[:mentioned]) + end + it "triggers :before_create_notifications_for_users" do events = DiscourseEvent.track_events do post