Skip to content

Node.js based forum software built for the modern web

test: fix load topic title that's already passed to notification functions

Barış Soner Uşaklı43a1d59e335d
diff --git a/src/categories/topics.js b/src/categories/topics.js
index b888be0b47..1ac5469d7b 100644
--- a/src/categories/topics.js
+++ b/src/categories/topics.js
@@ -217,7 +217,7 @@ module.exports = function (Categories) {
}
Categories.notifyCategoryFollowers = async (postData, exceptUid) => {
- const { cid } = postData.topic;
+ const { cid, title } = postData.topic;
const followers = [];
await batch.processSortedSet(`cid:${cid}:uid:watch:state`, async (uids) => {
followers.push(
@@ -236,16 +236,15 @@ module.exports = function (Categories) {
return;
}
- const [displayname, categoryName, title] = await Promise.all([
+ const [displayname, categoryName] = await Promise.all([
user.getNotificationDisplayname(postData.user.uid),
Categories.getCategoryField(cid, 'name'),
- topics.getNotificationTitle(postData.topic.tid),
]);
const bodyShort = tx.compile(
'notifications:user-posted-topic-in-category',
displayname,
- title,
+ tx.escape(title),
categoryName
);
diff --git a/src/topics/tags.js b/src/topics/tags.js
index fb86c1e4e9..e7a903214c 100644
--- a/src/topics/tags.js
+++ b/src/topics/tags.js
@@ -610,16 +610,15 @@ module.exports = function (Topics) {
};
Topics.notifyTagFollowers = async function (postData, exceptUid) {
- const { tags } = postData.topic;
+ const { tags, title } = postData.topic;
if (!tags.length) {
return;
}
- const [followersOfPoster, allFollowers, displayname, title] = await Promise.all([
+ const [followersOfPoster, allFollowers, displayname] = await Promise.all([
db.getSortedSetRange(`followers:${exceptUid}`, 0, -1),
db.getSortedSetRange(tags.map(tag => `tag:${tag.value}:followers`), 0, -1),
user.getNotificationDisplayname(exceptUid),
- Topics.getTopicField(postData.topic.tid, 'title'),
]);
const followerSet = new Set(followersOfPoster);
// filter out followers of the poster since they get a notification already
@@ -640,7 +639,7 @@ module.exports = function (Topics) {
suffix = '-multiple';
tagArgs = [tagArgs.join(', ')];
}
- const bodyShort = tx.compile(`${notifBase}${suffix}`, displayname, title, ...tagArgs);
+ const bodyShort = tx.compile(`${notifBase}${suffix}`, displayname, tx.escape(title), ...tagArgs);
const notification = await notifications.create({
type: 'new-topic-with-tag',
diff --git a/src/user/notifications.js b/src/user/notifications.js
index 585f52acc7..69d59fee8c 100644
--- a/src/user/notifications.js
+++ b/src/user/notifications.js
@@ -10,7 +10,6 @@ const notifications = require('../notifications');
const privileges = require('../privileges');
const plugins = require('../plugins');
const tx = require('../translator');
-const topics = require('../topics');
const posts = require('../posts');
const user = require('./index');
@@ -219,10 +218,9 @@ UserNotifications.deleteAll = async function (uid) {
UserNotifications.sendTopicNotificationToFollowers = async function (uid, topicData, postData) {
try {
- const [displayname, allFollowers, title] = await Promise.all([
+ const [displayname, allFollowers] = await Promise.all([
user.getNotificationDisplayname(uid),
db.getSortedSetRange(`followers:${uid}`, 0, -1),
- topics.getNotificationTitle(topicData.tid, 'title'),
]);
const followers = await privileges.categories.filterUids('topics:read', topicData.cid, allFollowers);
if (!followers.length) {
@@ -231,7 +229,7 @@ UserNotifications.sendTopicNotificationToFollowers = async function (uid, topicD
const notifObj = await notifications.create({
type: 'new-topic',
- bodyShort: tx.compile('notifications:user-posted-topic', displayname, title),
+ bodyShort: tx.compile('notifications:user-posted-topic', displayname, tx.escape(topicData.title)),
bodyLong: postData.content,
pid: postData.pid,
path: `/post/${postData.pid}`,