do a single filter after getting all unread tids

v1.18.x
barisusakli 11 years ago
parent 41ed52a414
commit b5cc852551

@ -23,48 +23,45 @@ module.exports = function(Topics) {
done = false; done = false;
uid = parseInt(uid, 10); uid = parseInt(uid, 10);
if(uid === 0) { if (uid === 0) {
return callback(null, unreadTids); return callback(null, unreadTids);
} }
async.whilst(function() { async.whilst(function() {
return unreadTids.length < 21 && !done; return unreadTids.length < 21 && !done;
}, function(callback) { }, function(next) {
Topics.getLatestTids(start, stop, 'month', function(err, tids) { Topics.getLatestTids(start, stop, 'month', function(err, tids) {
if (err) { if (err) {
return callback(err); return next(err);
} }
if (tids && !tids.length) { if (tids && !tids.length) {
done = true; done = true;
return callback(); return next();
} }
Topics.hasReadTopics(tids, uid, function(err, read) { Topics.hasReadTopics(tids, uid, function(err, read) {
if(err) { if (err) {
return callback(err); return next(err);
} }
var newtids = tids.filter(function(tid, index) { var newtids = tids.filter(function(tid, index) {
return !read[index]; return !read[index];
}); });
privileges.topics.filter('read', newtids, uid, function(err, newtids) { unreadTids.push.apply(unreadTids, newtids);
if(err) {
return callback(err);
}
unreadTids.push.apply(unreadTids, newtids);
start = stop + 1; start = stop + 1;
stop = start + 19; stop = start + 19;
callback(); next();
});
}); });
}); });
}, function(err) { }, function(err) {
callback(err, unreadTids); if (err) {
return callback(err);
}
privileges.topics.filter('read', unreadTids, uid, callback);
}); });
}; };

Loading…
Cancel
Save