Skip to content

Node.js based forum software built for the modern web

fix: notifications where bodyLong is a translation string

Barış Soner Uşaklı99691b2e160a
diff --git a/public/src/modules/translator.common.js b/public/src/modules/translator.common.js
index 7e4d4869a9..f074ad0557 100644
--- a/public/src/modules/translator.common.js
+++ b/public/src/modules/translator.common.js
@@ -487,6 +487,10 @@ module.exports = function (utils, load, warn) {
return this.rtlLanguages.includes(lang) ? 'rtl' : 'ltr';
},
+ isTranslationKey: function (str) {
+ return typeof str === 'string' && /\[\[([a-zA-Z0-9_.-]+:[^[\]]+)\]\]/.test(str);
+ },
+
flush: function () {
Object.keys(Translator.cache).forEach(function (code) {
Translator.cache[code].translations = {};
diff --git a/src/emailer.js b/src/emailer.js
index 9a361ebe32..61b455f3c0 100644
--- a/src/emailer.js
+++ b/src/emailer.js
@@ -242,11 +242,9 @@ Emailer.send = async (template, uid, params) => {
({ template, userData, params } = await Plugins.hooks.fire('filter:email.prepare', { template, uid, userData, params }));
- if (!meta.config.sendEmailToBanned && template !== 'banned') {
- if (userData.banned) {
- winston.warn(`[emailer/send] User ${userData.username} (uid: ${uid}) is banned; not sending email due to system config.`);
- return;
- }
+ if (userData.banned && !meta.config.sendEmailToBanned && template !== 'banned') {
+ winston.warn(`[emailer/send] User ${userData.username} (uid: ${uid}) is banned; not sending email due to system config.`);
+ return;
}
if (!userData || !userData.email) {
diff --git a/src/notifications.js b/src/notifications.js
index df1147c7d5..026de53f9c 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -196,6 +196,9 @@ Notifications.create = async function (data) {
if (data.bodyShort) {
data.bodyShort = utils.stripBidiControls(data.bodyShort);
}
+ if (data.bodyLong && tx.isTranslationKey(data.bodyLong)) {
+ data.txBodyLong = 1;
+ }
await Promise.all([
db.sortedSetAdd('notifications', now, data.nid),
db.setObject(`notifications:${data.nid}`, data),
diff --git a/src/socket.io/admin/email.js b/src/socket.io/admin/email.js
index f355b8ca4b..9059520b2b 100644
--- a/src/socket.io/admin/email.js
+++ b/src/socket.io/admin/email.js
@@ -10,7 +10,6 @@ const notifications = require('../../notifications');
const emailer = require('../../emailer');
const utils = require('../../utils');
const user = require('../../user');
-const tx = require('../../translator');
const Email = module.exports;
@@ -59,7 +58,7 @@ Email.test = async function (socket, data) {
path: notification.path,
subject: utils.stripHTMLTags(notification.subject || '[[notifications:new-notification]]'),
intro: utils.stripHTMLTags(notification.bodyShort),
- body: await tx.translate(notification.bodyLong || ''),
+ body: notification.bodyLong || '',
notification,
showUnsubscribe: true,
});
diff --git a/src/user/notifications.js b/src/user/notifications.js
index 3666c27505..17ac26dc34 100644
--- a/src/user/notifications.js
+++ b/src/user/notifications.js
@@ -137,6 +137,9 @@ UserNotifications.getNotifications = async function (nids, uid) {
if (n?.bodyShort) {
n.bodyShort = await tx.translate(n.bodyShort, userSettings.userLang);
}
+ if (n?.bodyLong && n?.txBodyLong) {
+ n.bodyLong = await tx.translate(n.bodyLong, userSettings.userLang);
+ }
}));
const result = await plugins.hooks.fire('filter:user.notifications.getNotifications', {
diff --git a/src/views/emails/notification.tpl b/src/views/emails/notification.tpl
index 7468811b24..3f5ee1396f 100644
--- a/src/views/emails/notification.tpl
+++ b/src/views/emails/notification.tpl
@@ -23,7 +23,7 @@
{{{ if (notification.type == "post-queue") }}}
<!-- IMPORT emails/partials/post-queue-body.tpl -->
{{{ else }}}
- {{body}}
+ {{{ if notification.txBodyLong }}}{{tx(body)}}{{{ else }}}{{body}}{{{ end }}}
{{{ end }}}
</p>
</td>