Node.js based forum software built for the modern web
fix: move the rendering of post-queue-body to notification.tpl
Barış Soner Uşaklı8d61107a0076
diff --git a/src/emailer.js b/src/emailer.jsindex ffd6968eaa..53ce022764 100644--- a/src/emailer.js+++ b/src/emailer.js@@ -377,8 +377,10 @@ Emailer.sendViaFallback = async (data) => {};Emailer.renderAndTranslate = async (template, params, lang) => {- const _i18n = languages.getFull(lang);- const html = await app.renderAsync(`emails/${template}`, { ...params, _i18n: _i18n });+ const html = await app.renderAsync(`emails/${template}`, {+ ...params,+ _i18n: languages.getFull(lang),+ });return await translator.translate(html, lang);};diff --git a/src/notifications.js b/src/notifications.jsindex 53f0c3ad62..df1147c7d5 100644--- a/src/notifications.js+++ b/src/notifications.js@@ -334,7 +334,7 @@ async function sendEmail({ uids, notification }, cacheKey, reason) {if (['new-reply', 'new-chat'].includes(notification.type)) {notification['cta-type'] = notification.type;}- let body = notification.bodyEmail || notification.bodyLong || '';+ let body = notification.bodyLong || '';if (meta.config.removeEmailNotificationImages) {body = body.replace(/<img[^>]*>/, '');}diff --git a/src/posts/queue.js b/src/posts/queue.jsindex b50b8fc777..d8a2de903e 100644--- a/src/posts/queue.js+++ b/src/posts/queue.js@@ -246,10 +246,6 @@ module.exports = function (Posts) {cache.del('post-queue');await plugins.hooks.fire('action:post-queue.save', payload);- const cid = await getCid(type, data);- const uids = await getNotificationUids(cid);- const bodyEmail = await parseBodyEmail(cid, type, data);-const typeToTx = {reply: '[[notifications:post-awaiting-review]]',@@ -269,11 +265,18 @@ module.exports = function (Posts) {mergeId: `post-queue-${type}-uid-${data.uid}`,bodyShort: typeToTx[type],bodyLong: bodyLong,- bodyEmail: bodyEmail,path: `/post-queue/${id}`,from: data.uid,});- await notifications.push(notifObj, uids);+ if (notifObj) {+ const cid = await getCid(type, data);+ const [uids, emailData] = await Promise.all([+ getNotificationUids(cid),+ getEmailData(cid, type, data),+ ]);+ await notifications.push({ ...notifObj, ...emailData }, uids);+ }+return {id: id,type: type,@@ -282,7 +285,7 @@ module.exports = function (Posts) {};};- async function parseBodyEmail(cid, type, data) {+ async function getEmailData(cid, type, data) {const url = nconf.get('url');const [content, category, userData] = await Promise.all([plugins.hooks.fire('filter:parse.raw', data.sourceContent || data.content),@@ -300,15 +303,7 @@ module.exports = function (Posts) {topic.title = await topics.getTopicField(data.tid, 'title');topic.url = `${url}/topic/${data.tid}`;}- const { app } = require('../webserver');- const _i18n = require('../languages').getFull(meta.config.defaultLang);- return await app.renderAsync('emails/partials/post-queue-body', {- _i18n,- content: content,- category: category,- user: userData,- topic: topic,- });+ return { content, category, topic, user: userData };}async function getCid(type, data) {diff --git a/src/views/emails/notification.tpl b/src/views/emails/notification.tplindex 3c34adf1bd..37439dcd50 100644--- a/src/views/emails/notification.tpl+++ b/src/views/emails/notification.tpl@@ -20,7 +20,11 @@<tr class="notification-body"><td style="padding: 20px 40px; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol; font-size: 15px; line-height: 20px; color: #555555;"><p style="margin: 0; padding: 6px 0px; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol; font-size: 13px; line-height: 26px; color: #666666;">+ {{{ if (notification.type == "post-queue") }}}+ <!-- IMPORT emails/partials/post-queue-body.tpl -->+ {{{ else }}}{{txEscape(body)}}+ {{{ end }}}</p></td></tr>diff --git a/src/views/emails/partials/post-queue-body.tpl b/src/views/emails/partials/post-queue-body.tplindex f32d5c15df..f65e6746cf 100644--- a/src/views/emails/partials/post-queue-body.tpl+++ b/src/views/emails/partials/post-queue-body.tpl@@ -1,9 +1,9 @@<p><strong>{{tx("post-queue:category")}}</strong></p>-<p><a href="{category.url}">{{tx(category.name)}}</a></p>+<p><a href="{notification.category.url}">{{tx(notification.category.name)}}</a></p>-<p><strong>{{{ if topic.tid }}}{{tx("post-queue:topic")}}{{{ else }}}{{tx("post-queue:title")}}{{{ end }}}</strong></p>-<p>{{{ if topic.url }}}<a href="{topic.url}">{topic.title}</a>{{{ else }}}{topic.title}{{{ end }}}</p>+<p><strong>{{{ if notification.topic.tid }}}{{tx("post-queue:topic")}}{{{ else }}}{{tx("post-queue:title")}}{{{ end }}}</strong></p>+<p>{{{ if notification.topic.url }}}<a href="{notification.topic.url}">{notification.topic.title}</a>{{{ else }}}{notification.topic.title}{{{ end }}}</p><p><strong>{{tx("post-queue:user")}}</strong></p>-<p>{{{ if user.url }}}<a href="{user.url}">{user.username}</a>{{{ else }}}{user.username}{{{ end }}}</p>-<p>{{txEscape(content)}}</p>+<p>{{{ if notification.user.url }}}<a href="{notification.user.url}">{notification.user.username}</a>{{{ else }}}{notification.user.username}{{{ end }}}</p>+<p>{{txEscape(notification.content)}}</p>