A platform for community discussion. Free, open, simple.
DEV: Modifier for Chat::Mailer to skip summary email for users (#26011)
Mark VanLandingham04b0f40db868
diff --git a/plugins/chat/lib/chat/mailer.rb b/plugins/chat/lib/chat/mailer.rbindex 1be1ae3259e..f3cf90fcbcc 100644--- a/plugins/chat/lib/chat/mailer.rb+++ b/plugins/chat/lib/chat/mailer.rb@@ -6,6 +6,11 @@ module Chatreturn unless SiteSetting.chat_enabledusers_with_unprocessed_unread_mentions.find_each do |user|+ # Apply modifier to `true` -- this allows other plugins to block the chat summary email send+ if !DiscoursePluginRegistry.apply_modifier(:chat_mailer_send_summary_to_user, true, user)+ next+ end+# user#memberships_with_unread_messages is a nested array that looks like [[membership_id, unread_message_id]]# Find the max unread id per membership.membership_and_max_unread_mention_ids =diff --git a/plugins/chat/spec/components/chat/mailer_spec.rb b/plugins/chat/spec/components/chat/mailer_spec.rbindex 3bfcb09c036..5a66196f39c 100644--- a/plugins/chat/spec/components/chat/mailer_spec.rb+++ b/plugins/chat/spec/components/chat/mailer_spec.rb@@ -235,6 +235,26 @@ describe Chat::Mailer doassert_only_queued_onceend+ context "with chat_mailer_send_summary_to_user modifier" do+ let(:modifier_block) { Proc.new { |_| false } }+ it "skips when modifier evaluates to false" do+ SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:everyone]++ plugin_instance = Plugin::Instance.new+ plugin_instance.register_modifier(:chat_mailer_send_summary_to_user, &modifier_block)++ described_class.send_unread_mentions_summary++ assert_summary_skipped+ ensure+ DiscoursePluginRegistry.unregister_modifier(+ plugin_instance,+ :chat_mailer_send_summary_to_user,+ &modifier_block+ )+ end+ end+describe "update the user membership after we send the email" dobefore { Jobs.run_immediately! }