From ceaedf9e2febb21be6672e01a889fbd0d94cbf7e Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 12 Aug 2014 13:02:07 -0400 Subject: [PATCH] closes #1941 --- src/topics/follow.js | 77 ++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/src/topics/follow.js b/src/topics/follow.js index e16cf99b9a..76fb14cf6a 100644 --- a/src/topics/follow.js +++ b/src/topics/follow.js @@ -22,49 +22,50 @@ module.exports = function(Topics) { }; Topics.notifyFollowers = function(tid, pid, exceptUid) { - async.parallel({ - nid: function(next) { - async.parallel({ - 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); - } + Topics.getFollowers(tid, function(err, followers) { + if (err || !Array.isArray(followers) || !followers.length) { + return; + } - 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 - }, next); - }); - }, - followers: function(next) { - Topics.getFollowers(tid, next); + var index = followers.indexOf(exceptUid.toString()); + if (index !== -1) { + followers.splice(index, 1); + } + + if (!followers.length) { + return; } - }, function(err, results) { - if (!err && results.followers.length) { - var index = results.followers.indexOf(exceptUid.toString()); - if (index !== -1) { - results.followers.splice(index, 1); + async.parallel({ + 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; } - 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); + } + }); + }); }); }; - }; \ No newline at end of file