Skip to content

Node.js based forum software built for the modern web

closes #1941

barisusakliceaedf9e2feb
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