mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: #9304, add category/topic/username to post queue notification emails
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
const _ = require('lodash');
|
||||
const validator = require('validator');
|
||||
const nconf = require('nconf');
|
||||
|
||||
const db = require('../database');
|
||||
const user = require('../user');
|
||||
@@ -149,12 +150,14 @@ module.exports = function (Posts) {
|
||||
|
||||
const cid = await getCid(type, data);
|
||||
const uids = await getNotificationUids(cid);
|
||||
const bodyLong = await parseBodyLong(cid, type, data);
|
||||
|
||||
const notifObj = await notifications.create({
|
||||
type: 'post-queue',
|
||||
nid: `post-queue-${id}`,
|
||||
mergeId: 'post-queue',
|
||||
bodyShort: '[[notifications:post_awaiting_review]]',
|
||||
bodyLong: await plugins.hooks.fire('filter:parse.raw', data.content),
|
||||
bodyLong: bodyLong,
|
||||
path: '/post-queue',
|
||||
});
|
||||
await notifications.push(notifObj, uids);
|
||||
@@ -166,6 +169,33 @@ module.exports = function (Posts) {
|
||||
};
|
||||
};
|
||||
|
||||
async function parseBodyLong(cid, type, data) {
|
||||
const url = nconf.get('url');
|
||||
const [content, category, userData] = await Promise.all([
|
||||
plugins.hooks.fire('filter:parse.raw', data.content),
|
||||
categories.getCategoryFields(cid, ['name', 'slug']),
|
||||
user.getUserFields(data.uid, ['uid', 'username']),
|
||||
]);
|
||||
|
||||
category.url = `${url}/category/${category.slug}`;
|
||||
if (userData.uid > 0) {
|
||||
userData.url = `${url}/uid/${userData.uid}`;
|
||||
}
|
||||
|
||||
const topic = { cid: cid, title: data.title, tid: data.tid };
|
||||
if (type === 'reply') {
|
||||
topic.title = await topics.getTopicField(data.tid, 'title');
|
||||
topic.url = `${url}/topic/${data.tid}`;
|
||||
}
|
||||
const { app } = require('../webserver');
|
||||
return await app.renderAsync('emails/partials/post-queue-body', {
|
||||
content: content,
|
||||
category: category,
|
||||
user: userData,
|
||||
topic: topic,
|
||||
});
|
||||
}
|
||||
|
||||
async function getCid(type, data) {
|
||||
if (type === 'topic') {
|
||||
return data.cid;
|
||||
|
||||
9
src/views/emails/partials/post-queue-body.tpl
Normal file
9
src/views/emails/partials/post-queue-body.tpl
Normal file
@@ -0,0 +1,9 @@
|
||||
<p><strong>[[post-queue:category]]</strong></p>
|
||||
<p><a href="{category.url}">{category.name}</a></p>
|
||||
|
||||
<p><strong>{{{ if topic.tid }}}[[post-queue:topic]]{{{ else }}}[[post-queue:title]]{{{ end }}}</strong></p>
|
||||
<p>{{{ if topic.url }}}<a href="{topic.url}">{topic.title}</a>{{{ else }}}{topic.title}{{{ end }}}</p>
|
||||
|
||||
<p><strong>[[post-queue:user]]</strong></p>
|
||||
<p>{{{ if user.url }}}<a href="{user.url}">{user.username}</a>{{{ else }}}{user.username}{{{ end }}}</p>
|
||||
<p>{content}</p>
|
||||
Reference in New Issue
Block a user