DEV: Add modifiers for plugins to customize push notification translation arguments (#25889)

This commit is contained in:
Mark VanLandingham
2024-02-27 14:03:55 -06:00
committed by GitHub
parent eea7af09fd
commit b426f85a81
6 changed files with 121 additions and 0 deletions

View File

@@ -60,6 +60,11 @@ module Jobs
translation_args = { username: @creator.username }
translation_args[:channel] = @chat_channel.title(user) unless @is_direct_message_channel
translation_args =
DiscoursePluginRegistry.apply_modifier(
:chat_notification_translation_args,
translation_args,
)
payload = {
username: @creator.username,

View File

@@ -62,6 +62,29 @@ RSpec.describe Jobs::Chat::NotifyWatching do
)
end
context "with chat_notification_translation_args plugin_modifier" do
let(:modifier_block) do
Proc.new do |args|
args[:username] = "Hijacked"
args
end
end
it "Allows for changes to the translation args" do
plugin_instance = Plugin::Instance.new
plugin_instance.register_modifier(:chat_notification_translation_args, &modifier_block)
messages = notification_messages_for(user2)
expect(messages.first.data[:translated_title]).to start_with("Hijacked")
ensure
DiscoursePluginRegistry.unregister_modifier(
plugin_instance,
:chat_notification_translation_args,
&modifier_block
)
end
end
context "when the channel is muted via membership preferences" do
before { membership2.update!(muted: true) }