mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: closes #8308, edit post notif for watched topic posts
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
"user_posted_to_dual" : "<strong>%1</strong> and <strong>%2</strong> have posted replies to: <strong>%3</strong>",
|
||||
"user_posted_to_multiple" : "<strong>%1</strong> and %2 others have posted replies to: <strong>%3</strong>",
|
||||
"user_posted_topic": "<strong>%1</strong> has posted a new topic: <strong>%2</strong>",
|
||||
"user_edited_post" : "<strong>%1</strong> has edited a post in <strong>%2</strong>",
|
||||
"user_started_following_you": "<strong>%1</strong> started following you.",
|
||||
"user_started_following_you_dual": "<strong>%1</strong> and <strong>%2</strong> started following you.",
|
||||
"user_started_following_you_multiple": "<strong>%1</strong> 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",
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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 });
|
||||
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user