v1.18.x
barisusakli 11 years ago
parent 1cf5c3145a
commit ceaedf9e2f

@ -22,49 +22,50 @@ module.exports = function(Topics) {
}; };
Topics.notifyFollowers = function(tid, pid, exceptUid) { Topics.notifyFollowers = function(tid, pid, exceptUid) {
async.parallel({ Topics.getFollowers(tid, function(err, followers) {
nid: function(next) { if (err || !Array.isArray(followers) || !followers.length) {
async.parallel({ return;
topicData: async.apply(Topics.getTopicFields, tid, ['title', 'slug']), }
username: async.apply(user.getUserField, exceptUid, 'username'),
postIndex: async.apply(posts.getPidIndex, pid),
postContent: function(next) {
async.waterfall([
async.apply(posts.getPostField, pid, 'content'),
function(content, next) {
postTools.parse(content, next);
}
], next);
}
}, function(err, results) {
if (err) {
return next(err);
}
notifications.create({ var index = followers.indexOf(exceptUid.toString());
bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]', if (index !== -1) {
bodyLong: results.postContent, followers.splice(index, 1);
path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.postIndex, }
uniqueId: 'topic:' + tid + ':uid:' + exceptUid,
tid: tid, if (!followers.length) {
from: exceptUid return;
}, next);
});
},
followers: function(next) {
Topics.getFollowers(tid, next);
} }
}, function(err, results) {
if (!err && results.followers.length) {
var index = results.followers.indexOf(exceptUid.toString()); async.parallel({
if (index !== -1) { topicData: async.apply(Topics.getTopicFields, tid, ['title', 'slug']),
results.followers.splice(index, 1); username: async.apply(user.getUserField, exceptUid, 'username'),
postIndex: async.apply(posts.getPidIndex, pid),
postContent: function(next) {
async.waterfall([
async.apply(posts.getPostField, pid, 'content'),
function(content, next) {
postTools.parse(content, next);
}
], next);
}
}, function(err, results) {
if (err) {
return;
} }
notifications.push(results.nid, results.followers); notifications.create({
} bodyShort: '[[notifications:user_posted_to, ' + results.username + ', ' + results.topicData.title + ']]',
bodyLong: results.postContent,
path: nconf.get('relative_path') + '/topic/' + results.topicData.slug + '/' + results.postIndex,
uniqueId: 'topic:' + tid + ':uid:' + exceptUid,
tid: tid,
from: exceptUid
}, function(err, nid) {
if (!err) {
notifications.push(nid, followers);
}
});
});
}); });
}; };
}; };
Loading…
Cancel
Save