diff --git a/install/data/defaults.json b/install/data/defaults.json
index 86fc1075c4..797347f20f 100644
--- a/install/data/defaults.json
+++ b/install/data/defaults.json
@@ -81,9 +81,11 @@
"notificationType_upvote": "notification",
"notificationType_new-topic": "notification",
"notificationType_new-reply": "notification",
+ "notificationType_post-edit": "notification",
"notificationType_follow": "notification",
"notificationType_new-chat": "notification",
"notificationType_group-invite": "notification",
+ "notificationType_group-request-membership": "notification",
"notificationType_mention": "notification",
"notificationType_new-register": "notification",
"notificationType_post-queue": "notification",
diff --git a/public/language/en-GB/notifications.json b/public/language/en-GB/notifications.json
index 3716089d71..7ce5515ca0 100644
--- a/public/language/en-GB/notifications.json
+++ b/public/language/en-GB/notifications.json
@@ -39,6 +39,7 @@
"user_posted_to_dual" : "%1 and %2 have posted replies to: %3",
"user_posted_to_multiple" : "%1 and %2 others have posted replies to: %3",
"user_posted_topic": "%1 has posted a new topic: %2",
+ "user_edited_post" : "%1 has edited a post in %2",
"user_started_following_you": "%1 started following you.",
"user_started_following_you_dual": "%1 and %2 started following you.",
"user_started_following_you_multiple": "%1 and %2 others started following you.",
@@ -59,6 +60,7 @@
"notificationType_upvote": "When someone upvotes your post",
"notificationType_new-topic": "When someone you follow posts a topic",
"notificationType_new-reply": "When a new reply is posted in a topic you are watching",
+ "notificationType_post-edit": "When a post is edited in a topic you are watching",
"notificationType_follow": "When someone starts following you",
"notificationType_new-chat": "When you receive a chat message",
"notificationType_group-invite": "When you receive a group invite",
diff --git a/src/notifications.js b/src/notifications.js
index 2159a0da9d..537a23db97 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -21,6 +21,7 @@ Notifications.baseTypes = [
'notificationType_upvote',
'notificationType_new-topic',
'notificationType_new-reply',
+ 'notificationType_post-edit',
'notificationType_follow',
'notificationType_new-chat',
'notificationType_group-invite',
diff --git a/src/posts/edit.js b/src/posts/edit.js
index fbe3590ada..b85f54e68b 100644
--- a/src/posts/edit.js
+++ b/src/posts/edit.js
@@ -52,6 +52,13 @@ module.exports = function (Posts) {
postData.cid = topic.cid;
postData.topic = topic;
+
+ await topics.notifyFollowers(postData, data.uid, {
+ type: 'post-edit',
+ bodyShort: translator.compile('notifications:user_edited_post', editor.username, postData.topic.title),
+ nid: 'edit_post:' + postData.pid + ':uid:' + data.uid,
+ });
+
plugins.fireHook('action:post.edit', { post: _.clone(postData), data: data, uid: data.uid });
require('./cache').del(String(postData.pid));
@@ -79,6 +86,7 @@ module.exports = function (Posts) {
return {
tid: tid,
cid: topicData.cid,
+ title: validator.escape(String(topicData.title)),
isMainPost: false,
renamed: false,
};
diff --git a/src/topics/create.js b/src/topics/create.js
index 88ed0b244d..884446a549 100644
--- a/src/topics/create.js
+++ b/src/topics/create.js
@@ -13,6 +13,7 @@ var meta = require('../meta');
var posts = require('../posts');
var privileges = require('../privileges');
var categories = require('../categories');
+const translator = require('../translator');
module.exports = function (Topics) {
Topics.create = async function (data) {
@@ -180,7 +181,13 @@ module.exports = function (Topics) {
user.setUserField(uid, 'lastonline', Date.now());
}
- Topics.notifyFollowers(postData, uid);
+ Topics.notifyFollowers(postData, uid, {
+ type: 'new-reply',
+ bodyShort: translator.compile('notifications:user_posted_to', postData.user.username, postData.topic.title),
+ nid: 'new_post:tid:' + postData.topic.tid + ':pid:' + postData.pid + ':uid:' + uid,
+ mergeId: 'notifications:user_posted_to|' + postData.topic.tid,
+ });
+
analytics.increment(['posts', 'posts:byCid:' + data.cid]);
plugins.fireHook('action:topic.reply', { post: _.clone(postData), data: data });
diff --git a/src/topics/follow.js b/src/topics/follow.js
index 872cb92ce9..4faaa40419 100644
--- a/src/topics/follow.js
+++ b/src/topics/follow.js
@@ -145,47 +145,37 @@ module.exports = function (Topics) {
return tids.filter((tid, index) => tid && !scores[index]);
};
- Topics.notifyFollowers = async function (postData, exceptUid) {
- var title;
- var titleEscaped;
-
+ Topics.notifyFollowers = async function (postData, exceptUid, notifData) {
+ notifData = notifData || {};
let followers = await Topics.getFollowers(postData.topic.tid);
-
- var index = followers.indexOf(exceptUid.toString());
+ const index = followers.indexOf(String(exceptUid));
if (index !== -1) {
followers.splice(index, 1);
}
followers = await privileges.topics.filterUids('topics:read', postData.topic.tid, followers);
-
if (!followers.length) {
return;
}
- title = postData.topic.title;
+ let title = postData.topic.title;
if (title) {
title = utils.decodeHTMLEntities(title);
- titleEscaped = title.replace(/%/g, '%').replace(/,/g, ',');
}
postData.content = posts.relativeToAbsolute(postData.content, posts.urlRegex);
postData.content = posts.relativeToAbsolute(postData.content, posts.imgRegex);
const notification = await notifications.create({
- type: 'new-reply',
subject: title,
- bodyShort: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + titleEscaped + ']]',
bodyLong: postData.content,
pid: postData.pid,
path: '/post/' + postData.pid,
- nid: 'new_post:tid:' + postData.topic.tid + ':pid:' + postData.pid + ':uid:' + exceptUid,
tid: postData.topic.tid,
from: exceptUid,
- mergeId: 'notifications:user_posted_to|' + postData.topic.tid,
topicTitle: title,
+ ...notifData,
});
- if (notification) {
- notifications.push(notification, followers);
- }
+ notifications.push(notification, followers);
};
};