From fd676a72432f95ae5eafaa440d7ee22e1a1a7ce5 Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Fri, 30 Dec 2022 15:01:07 -0300 Subject: [PATCH] Temporarily retire invites and unreacheable for group mentions. We don't want to potentially send hundreds of IDs through MB --- .../app/jobs/regular/chat_notify_watching.rb | 4 +- plugins/chat/lib/chat_notifier.rb | 10 ++-- plugins/chat/spec/lib/chat_notifier_spec.rb | 49 ------------------- 3 files changed, 6 insertions(+), 57 deletions(-) diff --git a/plugins/chat/app/jobs/regular/chat_notify_watching.rb b/plugins/chat/app/jobs/regular/chat_notify_watching.rb index 1abd2e8194..36dfd355e2 100644 --- a/plugins/chat/app/jobs/regular/chat_notify_watching.rb +++ b/plugins/chat/app/jobs/regular/chat_notify_watching.rb @@ -37,9 +37,9 @@ module Jobs ) .merge(User.not_suspended) - if global_mentions.include?("all") + if global_mentions.include?(Chat::ChatNotifier::ALL_KEYWORD) members = members.where(user_option: { ignore_channel_wide_mention: true }) - elsif global_mentions.include?("here") + elsif global_mentions.include?(Chat::ChatNotifier::HERE_KEYWORD) members = members.where("last_seen_at < ?", 5.minutes.ago) end diff --git a/plugins/chat/lib/chat_notifier.rb b/plugins/chat/lib/chat_notifier.rb index 5702892ea1..12025935ba 100644 --- a/plugins/chat/lib/chat_notifier.rb +++ b/plugins/chat/lib/chat_notifier.rb @@ -31,9 +31,10 @@ class Chat::ChatNotifier HERE_MENTIONS = :here_mentions GLOBAL_MENTIONS = :global_mentions STATIC_MENTION_TYPES = [DIRECT_MENTIONS, HERE_MENTIONS, GLOBAL_MENTIONS] + HERE_KEYWORD = 'here' + ALL_KEYWORD = 'all' MENTION_BATCH_SIZE = 250 - class << self def push_notification_tag(type, chat_channel_id) "#{Discourse.current_hostname}-chat-#{type}-#{chat_channel_id}" @@ -73,8 +74,8 @@ class Chat::ChatNotifier end global_mentions = [] - global_mentions << "all" if typed_global_mention? - global_mentions << "here" if typed_here_mention? + global_mentions << ALL_KEYWORD if typed_global_mention? + global_mentions << HERE_KEYWORD if typed_here_mention? notify_watching_users( mentioned_channel_member_ids, @@ -168,9 +169,6 @@ class Chat::ChatNotifier classified.each do |group_name, member_ids| notify_mentioned_users(group_name, member_ids) end - - inaccessible_mentions[:welcome_to_join] = inaccessible_mentions[:welcome_to_join].concat(grouped[:welcome_to_join]) - inaccessible_mentions[:unreachable] = inaccessible_mentions[:unreachable].concat(grouped[:unreachable]) end end diff --git a/plugins/chat/spec/lib/chat_notifier_spec.rb b/plugins/chat/spec/lib/chat_notifier_spec.rb index 9118f08037..d0680dea10 100644 --- a/plugins/chat/spec/lib/chat_notifier_spec.rb +++ b/plugins/chat/spec/lib/chat_notifier_spec.rb @@ -335,31 +335,6 @@ describe Chat::ChatNotifier do unreachable_users = unreachable_msg.data[:cannot_see].map { |u| u["id"] } expect(unreachable_users).to contain_exactly(user_3.id) end - - it "notify posts of users who are part of the mentioned group but participating" do - group = - Fabricate( - :public_group, - users: [user_2, user_3], - mentionable_level: Group::ALIAS_LEVELS[:everyone], - ) - msg = - build_cooked_msg("Hello @#{group.name}", user_1, chat_channel: personal_chat_channel) - - messages = - MessageBus.track_publish("/chat/#{personal_chat_channel.id}") do - described_class.new(msg, msg.created_at).notify_new - - assert_users_were_notifier_with_mention_type(group.name, [user_2.id]) - end - - unreachable_msg = messages.first - - expect(unreachable_msg).to be_present - expect(unreachable_msg.data[:without_membership]).to be_empty - unreachable_users = unreachable_msg.data[:cannot_see].map { |u| u["id"] } - expect(unreachable_users).to contain_exactly(user_3.id) - end end end @@ -438,30 +413,6 @@ describe Chat::ChatNotifier do expect(not_participating_users).to contain_exactly(user_3.id) end - it "can invite other group members to channel" do - group = - Fabricate( - :public_group, - users: [user_2, user_3], - mentionable_level: Group::ALIAS_LEVELS[:everyone], - ) - msg = build_cooked_msg("Hello @#{group.name}", user_1) - - messages = - MessageBus.track_publish("/chat/#{channel.id}") do - described_class.new(msg, msg.created_at).notify_new - - assert_users_were_notifier_with_mention_type(:direct_mentions, []) - end - - not_participating_msg = messages.first - - expect(not_participating_msg).to be_present - expect(not_participating_msg.data[:cannot_see]).to be_empty - not_participating_users = not_participating_msg.data[:without_membership].map { |u| u["id"] } - expect(not_participating_users).to contain_exactly(user_3.id) - end - it "cannot invite a member of a group who is ignoring the user who created the message" do group = Fabricate(