From 68bb7c5a66d97e3394361c8255e0cb8a61f8a1e1 Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Tue, 14 Sep 2021 09:57:38 -0500 Subject: [PATCH] DEV: Support translated title in desktop/notifications (#14325) --- .../discourse/app/lib/desktop-notifications.js | 12 +++++++----- app/models/notification.rb | 6 ++++-- app/services/push_notification_pusher.rb | 2 +- spec/models/notification_spec.rb | 2 ++ spec/requests/api/schemas/json/site_response.json | 3 +++ 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/desktop-notifications.js b/app/assets/javascripts/discourse/app/lib/desktop-notifications.js index 5e6053b43bc..bbc48991478 100644 --- a/app/assets/javascripts/discourse/app/lib/desktop-notifications.js +++ b/app/assets/javascripts/discourse/app/lib/desktop-notifications.js @@ -153,11 +153,13 @@ function onNotification(data, siteSettings, user) { return; } - const notificationTitle = I18n.t(i18nKey(data.notification_type), { - site_title: siteSettings.title, - topic: data.topic_title, - username: formatUsername(data.username), - }); + const notificationTitle = + data.translated_title || + I18n.t(i18nKey(data.notification_type), { + site_title: siteSettings.title, + topic: data.topic_title, + username: formatUsername(data.username), + }); const notificationBody = data.excerpt; diff --git a/app/models/notification.rb b/app/models/notification.rb index a22be0e901c..bf91b350c2b 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -75,7 +75,8 @@ class Notification < ActiveRecord::Base DB.exec(<<~SQL) DELETE FROM notifications n - WHERE high_priority AND notification_type <> #{types[:chat_mention].to_i} + WHERE high_priority + AND notification_type NOT IN (#{types[:chat_mention].to_i}, #{types[:chat_message].to_i}) AND NOT EXISTS ( SELECT 1 FROM posts p @@ -117,7 +118,8 @@ class Notification < ActiveRecord::Base votes_released: 26, event_reminder: 27, event_invitation: 28, - chat_mention: 29 + chat_mention: 29, + chat_message: 30, ) end diff --git a/app/services/push_notification_pusher.rb b/app/services/push_notification_pusher.rb index 33872d599ae..3e0e4dc08a3 100644 --- a/app/services/push_notification_pusher.rb +++ b/app/services/push_notification_pusher.rb @@ -7,7 +7,7 @@ class PushNotificationPusher def self.push(user, payload) I18n.with_locale(user.effective_locale) do message = { - title: I18n.t( + title: payload[:translated_title] || I18n.t( "discourse_push_notifications.popup.#{Notification.types[payload[:notification_type]]}", site_title: SiteSetting.title, topic: payload[:topic_title], diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index e609a6063c0..9afd1d86513 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -48,6 +48,8 @@ describe Notification do expect(@types[:votes_released]).to eq(26) expect(@types[:event_reminder]).to eq(27) expect(@types[:event_invitation]).to eq(28) + expect(@types[:chat_mention]).to eq(29) + expect(@types[:chat_message]).to eq(30) end end end diff --git a/spec/requests/api/schemas/json/site_response.json b/spec/requests/api/schemas/json/site_response.json index 2781ff62d53..bda5dad96a4 100644 --- a/spec/requests/api/schemas/json/site_response.json +++ b/spec/requests/api/schemas/json/site_response.json @@ -94,6 +94,9 @@ }, "chat_mention": { "type": "integer" + }, + "chat_message": { + "type": "integer" } }, "required": [