v1.18.x
barisusakli 11 years ago
parent 80250b6f6c
commit 7fa014e5ad

@ -11,6 +11,7 @@ var async = require('async'),
posts = require('../posts'), posts = require('../posts'),
postTools = require('../postTools'), postTools = require('../postTools'),
notifications = require('../notifications'), notifications = require('../notifications'),
privileges = require('../privileges'),
meta = require('../meta'), meta = require('../meta'),
emailer = require('../emailer'); emailer = require('../emailer');
@ -96,60 +97,73 @@ module.exports = function(Topics) {
db.getSetMembers('tid:' + tid + ':followers', callback); db.getSetMembers('tid:' + tid + ':followers', callback);
}; };
Topics.notifyFollowers = function(postData, exceptUid) { Topics.notifyFollowers = function(postData, exceptUid, callback) {
Topics.getFollowers(postData.topic.tid, function(err, followers) { callback = callback || function() {};
if (err || !Array.isArray(followers) || !followers.length) { var followers, title;
return;
}
var index = followers.indexOf(exceptUid.toString()); async.waterfall([
if (index !== -1) { function(next) {
followers.splice(index, 1); Topics.getFollowers(postData.topic.tid, next);
} },
function(followers, next) {
if (!followers.length) { if (!Array.isArray(followers) || !followers.length) {
return; return callback();
} }
var index = followers.indexOf(exceptUid.toString());
var title = postData.topic.title; if (index !== -1) {
if (title) { followers.splice(index, 1);
title = S(title).decodeHTMLEntities().s; }
} if (!followers.length) {
return callback();
notifications.create({
bodyShort: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + title + ']]',
bodyLong: postData.content,
pid: postData.pid,
nid: 'tid:' + postData.topic.tid + ':pid:' + postData.pid + ':uid:' + exceptUid,
tid: postData.topic.tid,
from: exceptUid
}, function(err, notification) {
if (!err && notification) {
notifications.push(notification, followers);
} }
});
async.eachLimit(followers, 3, function(toUid, next) { privileges.categories.filterUids('read', postData.topic.cid, followers, next);
async.parallel({ },
userData: async.apply(user.getUserFields, toUid, ['username']), function(_followers, next) {
userSettings: async.apply(user.getSettings, toUid) followers = _followers;
}, function(err, data) { if (!followers.length) {
if (data.userSettings.hasOwnProperty('sendPostNotifications') && data.userSettings.sendPostNotifications) { return callback();
emailer.send('notif_post', toUid, { }
pid: postData.pid, title = postData.topic.title;
subject: '[' + (meta.config.title || 'NodeBB') + '] ' + title, if (title) {
intro: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + title + ']]', title = S(title).decodeHTMLEntities().s;
postBody: postData.content, }
site_title: meta.config.title || 'NodeBB',
username: data.userData.username, notifications.create({
url: nconf.get('url') + '/topic/' + postData.topic.tid, bodyShort: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + title + ']]',
base_url: nconf.get('url') bodyLong: postData.content,
}, next); pid: postData.pid,
} else { nid: 'tid:' + postData.topic.tid + ':pid:' + postData.pid + ':uid:' + exceptUid,
winston.debug('[topics.notifyFollowers] uid ' + toUid + ' does not have post notifications enabled, skipping.'); tid: postData.topic.tid,
} from: exceptUid
}, next);
},
function(notification, next) {
notifications.push(notification, followers);
async.eachLimit(followers, 3, function(toUid, next) {
async.parallel({
userData: async.apply(user.getUserFields, toUid, ['username']),
userSettings: async.apply(user.getSettings, toUid)
}, function(err, data) {
if (data.userSettings.hasOwnProperty('sendPostNotifications') && data.userSettings.sendPostNotifications) {
emailer.send('notif_post', toUid, {
pid: postData.pid,
subject: '[' + (meta.config.title || 'NodeBB') + '] ' + title,
intro: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + title + ']]',
postBody: postData.content,
site_title: meta.config.title || 'NodeBB',
username: data.userData.username,
url: nconf.get('url') + '/topic/' + postData.topic.tid,
base_url: nconf.get('url')
}, next);
} else {
winston.debug('[topics.notifyFollowers] uid ' + toUid + ' does not have post notifications enabled, skipping.');
}
});
}); });
}); next();
}); }
], callback);
}; };
}; };
Loading…
Cancel
Save