v1.18.x
barisusakli 10 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());
if (index !== -1) {
followers.splice(index, 1);
}
if (!followers.length) {
return;
}
var title = postData.topic.title; async.waterfall([
if (title) { function(next) {
title = S(title).decodeHTMLEntities().s; Topics.getFollowers(postData.topic.tid, next);
} },
function(followers, next) {
if (!Array.isArray(followers) || !followers.length) {
return callback();
}
var index = followers.indexOf(exceptUid.toString());
if (index !== -1) {
followers.splice(index, 1);
}
if (!followers.length) {
return callback();
}
notifications.create({ privileges.categories.filterUids('read', postData.topic.cid, followers, next);
bodyShort: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + title + ']]', },
bodyLong: postData.content, function(_followers, next) {
pid: postData.pid, followers = _followers;
nid: 'tid:' + postData.topic.tid + ':pid:' + postData.pid + ':uid:' + exceptUid, if (!followers.length) {
tid: postData.topic.tid, return callback();
from: exceptUid }
}, function(err, notification) { title = postData.topic.title;
if (!err && notification) { if (title) {
notifications.push(notification, followers); title = S(title).decodeHTMLEntities().s;
} }
});
async.eachLimit(followers, 3, function(toUid, next) { notifications.create({
async.parallel({ bodyShort: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + title + ']]',
userData: async.apply(user.getUserFields, toUid, ['username']), bodyLong: postData.content,
userSettings: async.apply(user.getSettings, toUid) pid: postData.pid,
}, function(err, data) { nid: 'tid:' + postData.topic.tid + ':pid:' + postData.pid + ':uid:' + exceptUid,
if (data.userSettings.hasOwnProperty('sendPostNotifications') && data.userSettings.sendPostNotifications) { tid: postData.topic.tid,
emailer.send('notif_post', toUid, { from: exceptUid
pid: postData.pid, }, next);
subject: '[' + (meta.config.title || 'NodeBB') + '] ' + title, },
intro: '[[notifications:user_posted_to, ' + postData.user.username + ', ' + title + ']]', function(notification, next) {
postBody: postData.content, notifications.push(notification, followers);
site_title: meta.config.title || 'NodeBB',
username: data.userData.username, async.eachLimit(followers, 3, function(toUid, next) {
url: nconf.get('url') + '/topic/' + postData.topic.tid, async.parallel({
base_url: nconf.get('url') userData: async.apply(user.getUserFields, toUid, ['username']),
}, next); userSettings: async.apply(user.getSettings, toUid)
} else { }, function(err, data) {
winston.debug('[topics.notifyFollowers] uid ' + toUid + ' does not have post notifications enabled, skipping.'); 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