DEV: Support translated title in desktop/notifications (#14325)

DEV: Support translated title in desktop/notifications (#14325)

diff --git a/app/assets/javascripts/discourse/app/lib/desktop-notifications.js b/app/assets/javascripts/discourse/app/lib/desktop-notifications.js
index 5e6053b..bbc4899 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 a22be0e..bf91b35 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 33872d5..3e0e4dc 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 e609a60..9afd1d8 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 2781ff6..bda5dad 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": [

GitHub sha: 68bb7c5a66d97e3394361c8255e0cb8a61f8a1e1

This commit appears in #14325 which was approved by eviltrout and Falco. It was merged by markvanlan.