|
|
|
@ -11,6 +11,7 @@ var async = require('async'),
|
|
|
|
|
posts = require('../posts'),
|
|
|
|
|
postTools = require('../postTools'),
|
|
|
|
|
notifications = require('../notifications'),
|
|
|
|
|
privileges = require('../privileges'),
|
|
|
|
|
meta = require('../meta'),
|
|
|
|
|
emailer = require('../emailer');
|
|
|
|
|
|
|
|
|
@ -96,22 +97,34 @@ module.exports = function(Topics) {
|
|
|
|
|
db.getSetMembers('tid:' + tid + ':followers', callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Topics.notifyFollowers = function(postData, exceptUid) {
|
|
|
|
|
Topics.getFollowers(postData.topic.tid, function(err, followers) {
|
|
|
|
|
if (err || !Array.isArray(followers) || !followers.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Topics.notifyFollowers = function(postData, exceptUid, callback) {
|
|
|
|
|
callback = callback || function() {};
|
|
|
|
|
var followers, title;
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function(next) {
|
|
|
|
|
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;
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var title = postData.topic.title;
|
|
|
|
|
privileges.categories.filterUids('read', postData.topic.cid, followers, next);
|
|
|
|
|
},
|
|
|
|
|
function(_followers, next) {
|
|
|
|
|
followers = _followers;
|
|
|
|
|
if (!followers.length) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
title = postData.topic.title;
|
|
|
|
|
if (title) {
|
|
|
|
|
title = S(title).decodeHTMLEntities().s;
|
|
|
|
|
}
|
|
|
|
@ -123,11 +136,10 @@ module.exports = function(Topics) {
|
|
|
|
|
nid: 'tid:' + postData.topic.tid + ':pid:' + postData.pid + ':uid:' + exceptUid,
|
|
|
|
|
tid: postData.topic.tid,
|
|
|
|
|
from: exceptUid
|
|
|
|
|
}, function(err, notification) {
|
|
|
|
|
if (!err && notification) {
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function(notification, next) {
|
|
|
|
|
notifications.push(notification, followers);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async.eachLimit(followers, 3, function(toUid, next) {
|
|
|
|
|
async.parallel({
|
|
|
|
@ -150,6 +162,8 @@ module.exports = function(Topics) {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
};
|