From 3b0b4e118cabb2f51930f67db08ddd434273bdc8 Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Thu, 7 Mar 2024 09:47:21 -0600 Subject: [PATCH] DEV: Include group_name in push notification payload for group mentions (#26081) --- .../app/lib/desktop-notifications.js | 1 + app/services/post_alerter.rb | 21 +++++++++++++++++-- app/services/push_notification_pusher.rb | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/desktop-notifications.js b/app/assets/javascripts/discourse/app/lib/desktop-notifications.js index 7a43ecbb70c..6cf190f001b 100644 --- a/app/assets/javascripts/discourse/app/lib/desktop-notifications.js +++ b/app/assets/javascripts/discourse/app/lib/desktop-notifications.js @@ -167,6 +167,7 @@ async function onNotification(data, siteSettings, user, appEvents) { site_title: siteSettings.title, topic: data.topic_title, username: formatUsername(data.username), + group_name: data.group_name, }); const notificationBody = data.excerpt; diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index da1235300f9..1cff1d0e826 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -13,7 +13,14 @@ class PostAlerter post end - def self.create_notification_alert(user:, post:, notification_type:, excerpt: nil, username: nil) + def self.create_notification_alert( + user:, + post:, + notification_type:, + excerpt: nil, + username: nil, + group_name: nil + ) return if user.suspended? if post_url = post.url @@ -34,6 +41,7 @@ class PostAlerter username: username || post.username, post_url: post_url, } + payload[:group_name] = group_name if group_name.present? DiscourseEvent.trigger(:pre_notification_alert, user, payload) @@ -655,19 +663,28 @@ class PostAlerter post: original_post, notification_type: type, username: original_username, + group_name: group&.name, ) end created.id ? created : nil end - def create_notification_alert(user:, post:, notification_type:, excerpt: nil, username: nil) + def create_notification_alert( + user:, + post:, + notification_type:, + excerpt: nil, + username: nil, + group_name: nil + ) self.class.create_notification_alert( user: user, post: post, notification_type: notification_type, excerpt: excerpt, username: username, + group_name: group_name, ) end diff --git a/app/services/push_notification_pusher.rb b/app/services/push_notification_pusher.rb index b0fdbebec8c..b15e179d24c 100644 --- a/app/services/push_notification_pusher.rb +++ b/app/services/push_notification_pusher.rb @@ -58,6 +58,7 @@ class PushNotificationPusher site_title: SiteSetting.title, topic: payload[:topic_title], username: payload[:username], + group_name: payload[:group_name], ) end