DEV: Modifier for Chat::Mailer to skip summary email for users (#26011)
This commit is contained in:
parent
f7d7092a7a
commit
04b0f40db8
|
@ -6,6 +6,11 @@ module Chat
|
|||
return unless SiteSetting.chat_enabled
|
||||
|
||||
users_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 =
|
||||
|
|
|
@ -235,6 +235,26 @@ describe Chat::Mailer do
|
|||
assert_only_queued_once
|
||||
end
|
||||
|
||||
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" do
|
||||
before { Jobs.run_immediately! }
|
||||
|
||||
|
|
Loading…
Reference in New Issue