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