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

@ -22,8 +22,20 @@ 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) {
return;
}
var index = followers.indexOf(exceptUid.toString());
if (index !== -1) {
followers.splice(index, 1);
}
if (!followers.length) {
return;
}
async.parallel({ async.parallel({
topicData: async.apply(Topics.getTopicFields, tid, ['title', 'slug']), topicData: async.apply(Topics.getTopicFields, tid, ['title', 'slug']),
username: async.apply(user.getUserField, exceptUid, 'username'), username: async.apply(user.getUserField, exceptUid, 'username'),
@ -38,7 +50,7 @@ module.exports = function(Topics) {
} }
}, function(err, results) { }, function(err, results) {
if (err) { if (err) {
return next(err); return;
} }
notifications.create({ notifications.create({
@ -48,23 +60,12 @@ module.exports = function(Topics) {
uniqueId: 'topic:' + tid + ':uid:' + exceptUid, uniqueId: 'topic:' + tid + ':uid:' + exceptUid,
tid: tid, tid: tid,
from: exceptUid from: exceptUid
}, next); }, function(err, nid) {
}); if (!err) {
}, notifications.push(nid, followers);
followers: function(next) {
Topics.getFollowers(tid, next);
}
}, function(err, results) {
if (!err && results.followers.length) {
var index = results.followers.indexOf(exceptUid.toString());
if (index !== -1) {
results.followers.splice(index, 1);
}
notifications.push(results.nid, results.followers);
} }
}); });
});
});
}; };
}; };
Loading…
Cancel
Save