A platform for community discussion. Free, open, simple.
FIX: exclude bots of inaccessible/unreachable mentions (#31458)
Joffrey JAFFEUX3d5a1858e5bb
diff --git a/plugins/chat/lib/chat/notifier.rb b/plugins/chat/lib/chat/notifier.rbindex 28cf6fd618e..54f3f0cc3bc 100644--- a/plugins/chat/lib/chat/notifier.rb+++ b/plugins/chat/lib/chat/notifier.rb@@ -104,8 +104,6 @@ module Chatto_notifyend- private-def list_users_to_notifyskip_notifications = @parsed_mentions.count > SiteSetting.max_mentions_per_chat_message@@ -127,6 +125,8 @@ module Chat[to_notify, inaccessible, all_mentioned_user_ids]end+ private+def expand_global_mention(to_notify, already_covered_ids)has_all_mention = @parsed_mentions.has_global_mention@@ -172,8 +172,8 @@ module Chat{members: members || [],- welcome_to_join: welcome_to_join || [],- unreachable: unreachable || [],+ welcome_to_join: (welcome_to_join || []).select(&:human?),+ unreachable: (unreachable || []).select(&:human?),}enddiff --git a/plugins/chat/spec/lib/chat/notifier_spec.rb b/plugins/chat/spec/lib/chat/notifier_spec.rbindex 0dd2d1df77e..f47b46dab2a 100644--- a/plugins/chat/spec/lib/chat/notifier_spec.rb+++ b/plugins/chat/spec/lib/chat/notifier_spec.rb@@ -277,6 +277,25 @@ describe Chat::Notifier doexpect(to_notify[:direct_mentions]).to contain_exactly(user_2.id)end+ it "doesn’t attempt to notify bots not in the channel" do+ bot = Fabricate(:user, username: "bot", id: -999)++ msg = build_cooked_msg("Hello @bot", user_1)+ _, inaccessible, _ = described_class.new(msg, msg.created_at).list_users_to_notify++ expect(inaccessible[:welcome_to_join]).to be_empty++ msg =+ build_cooked_msg(+ "Hello @bot",+ user_1,+ chat_channel: Fabricate(:private_category_channel, group: Fabricate(:group)),+ )+ _, inaccessible, _ = described_class.new(msg, msg.created_at).list_users_to_notify++ expect(inaccessible[:unreachable]).to be_empty+ end+it "include users as direct mentions even if there's a @all mention" domsg = build_cooked_msg("Hello @all and @#{user_2.username}", user_1)