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

This commit is contained in:
Mark VanLandingham 2021-09-14 09:57:38 -05:00 committed by GitHub
parent e263b84196
commit 68bb7c5a66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 8 deletions

View File

@ -153,7 +153,9 @@ function onNotification(data, siteSettings, user) {
return; return;
} }
const notificationTitle = I18n.t(i18nKey(data.notification_type), { const notificationTitle =
data.translated_title ||
I18n.t(i18nKey(data.notification_type), {
site_title: siteSettings.title, site_title: siteSettings.title,
topic: data.topic_title, topic: data.topic_title,
username: formatUsername(data.username), username: formatUsername(data.username),

View File

@ -75,7 +75,8 @@ class Notification < ActiveRecord::Base
DB.exec(<<~SQL) DB.exec(<<~SQL)
DELETE DELETE
FROM notifications n 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 ( AND NOT EXISTS (
SELECT 1 SELECT 1
FROM posts p FROM posts p
@ -117,7 +118,8 @@ class Notification < ActiveRecord::Base
votes_released: 26, votes_released: 26,
event_reminder: 27, event_reminder: 27,
event_invitation: 28, event_invitation: 28,
chat_mention: 29 chat_mention: 29,
chat_message: 30,
) )
end end

View File

@ -7,7 +7,7 @@ class PushNotificationPusher
def self.push(user, payload) def self.push(user, payload)
I18n.with_locale(user.effective_locale) do I18n.with_locale(user.effective_locale) do
message = { message = {
title: I18n.t( title: payload[:translated_title] || I18n.t(
"discourse_push_notifications.popup.#{Notification.types[payload[:notification_type]]}", "discourse_push_notifications.popup.#{Notification.types[payload[:notification_type]]}",
site_title: SiteSetting.title, site_title: SiteSetting.title,
topic: payload[:topic_title], topic: payload[:topic_title],

View File

@ -48,6 +48,8 @@ describe Notification do
expect(@types[:votes_released]).to eq(26) expect(@types[:votes_released]).to eq(26)
expect(@types[:event_reminder]).to eq(27) expect(@types[:event_reminder]).to eq(27)
expect(@types[:event_invitation]).to eq(28) expect(@types[:event_invitation]).to eq(28)
expect(@types[:chat_mention]).to eq(29)
expect(@types[:chat_message]).to eq(30)
end end
end end
end end

View File

@ -94,6 +94,9 @@
}, },
"chat_mention": { "chat_mention": {
"type": "integer" "type": "integer"
},
"chat_message": {
"type": "integer"
} }
}, },
"required": [ "required": [