|
|
@ -145,47 +145,37 @@ module.exports = function (Topics) {
|
|
|
|
return tids.filter((tid, index) => tid && !scores[index]);
|
|
|
|
return tids.filter((tid, index) => tid && !scores[index]);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Topics.notifyFollowers = async function (postData, exceptUid) {
|
|
|
|
Topics.notifyFollowers = async function (postData, exceptUid, notifData) {
|
|
|
|
var title;
|
|
|
|
notifData = notifData || {};
|
|
|
|
var titleEscaped;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let followers = await Topics.getFollowers(postData.topic.tid);
|
|
|
|
let followers = await Topics.getFollowers(postData.topic.tid);
|
|
|
|
|
|
|
|
const index = followers.indexOf(String(exceptUid));
|
|
|
|
var index = followers.indexOf(exceptUid.toString());
|
|
|
|
|
|
|
|
if (index !== -1) {
|
|
|
|
if (index !== -1) {
|
|
|
|
followers.splice(index, 1);
|
|
|
|
followers.splice(index, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
followers = await privileges.topics.filterUids('topics:read', postData.topic.tid, followers);
|
|
|
|
followers = await privileges.topics.filterUids('topics:read', postData.topic.tid, followers);
|
|
|
|
|
|
|
|
|
|
|
|
if (!followers.length) {
|
|
|
|
if (!followers.length) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
title = postData.topic.title;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let title = postData.topic.title;
|
|
|
|
if (title) {
|
|
|
|
if (title) {
|
|
|
|
title = utils.decodeHTMLEntities(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.urlRegex);
|
|
|
|
postData.content = posts.relativeToAbsolute(postData.content, posts.imgRegex);
|
|
|
|
postData.content = posts.relativeToAbsolute(postData.content, posts.imgRegex);
|
|
|
|
|
|
|
|
|
|
|
|
const notification = await notifications.create({
|
|
|
|
const notification = await notifications.create({
|
|
|
|
type: 'new-reply',
|
|
|
|
|
|
|
|
subject: title,
|
|
|
|
subject: title,
|
|
|
|
bodyShort: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + titleEscaped + ']]',
|
|
|
|
|
|
|
|
bodyLong: postData.content,
|
|
|
|
bodyLong: postData.content,
|
|
|
|
pid: postData.pid,
|
|
|
|
pid: postData.pid,
|
|
|
|
path: '/post/' + postData.pid,
|
|
|
|
path: '/post/' + postData.pid,
|
|
|
|
nid: 'new_post:tid:' + postData.topic.tid + ':pid:' + postData.pid + ':uid:' + exceptUid,
|
|
|
|
|
|
|
|
tid: postData.topic.tid,
|
|
|
|
tid: postData.topic.tid,
|
|
|
|
from: exceptUid,
|
|
|
|
from: exceptUid,
|
|
|
|
mergeId: 'notifications:user_posted_to|' + postData.topic.tid,
|
|
|
|
|
|
|
|
topicTitle: title,
|
|
|
|
topicTitle: title,
|
|
|
|
|
|
|
|
...notifData,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
if (notification) {
|
|
|
|
notifications.push(notification, followers);
|
|
|
|
notifications.push(notification, followers);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|