DEV: Add push notification filtering to MessageBus alerts (#25965)

This commit is contained in:
Mark VanLandingham
2024-02-29 12:49:46 -06:00
committed by GitHub
parent f0baa0ddfe
commit 6c2c690479
4 changed files with 49 additions and 14 deletions

View File

@@ -76,7 +76,17 @@ module Jobs
}
if membership.desktop_notifications_always? && !membership.muted?
::MessageBus.publish("/chat/notification-alert/#{user.id}", payload, user_ids: [user.id])
send_notification =
DiscoursePluginRegistry.push_notification_filters.all? do |filter|
filter.call(user, payload)
end
if send_notification
::MessageBus.publish(
"/chat/notification-alert/#{user.id}",
payload,
user_ids: [user.id],
)
end
end
if membership.mobile_notifications_always? && !membership.muted?

View File

@@ -85,6 +85,16 @@ RSpec.describe Jobs::Chat::NotifyWatching do
end
end
context "with push_notification_filter registered to block push notifications" do
after { DiscoursePluginRegistry.reset_register!(:push_notification_filters) }
it "doesn't send notification alert via MessageBus" do
Plugin::Instance.new.register_push_notification_filter { |user, payload| false }
expect(notification_messages_for(user2)).to be_empty
end
end
context "when the channel is muted via membership preferences" do
before { membership2.update!(muted: true) }