replies change

v1.18.x
barisusakli 8 years ago
parent 570efb9e4b
commit 4f02775bdf

@ -389,43 +389,57 @@ module.exports = function (Topics) {
}; };
function getPostReplies(pids, callerUid, callback) { function getPostReplies(pids, callerUid, callback) {
async.map(pids, function (pid, next) { var uids = [];
db.getSortedSetRange('pid:' + pid + ':replies', 0, -1, function (err, replyPids) { var count = 0;
var uids = [], count = 0; var replyPids;
async.map(pids, function (pid, _next) {
async.until(function () { async.waterfall([
return count === replyPids.length || uids.length === 6; function (next) {
}, function (next) { db.getSortedSetRange('pid:' + pid + ':replies', 0, -1, next);
posts.getPostField(replyPids[count], 'uid', function (err, uid) { },
uid = parseInt(uid, 10); function (_replyPids, next) {
if (uids.indexOf(uid) === -1) { replyPids = _replyPids;
uids.push(uid); if (!replyPids.length) {
} return _next(null, {count: 0});
count++; }
next(err); async.until(function () {
}); return count === replyPids.length || uids.length === 6;
}, function (err) { }, function (next) {
posts.getPostField(replyPids[count], 'uid', function (err, uid) {
if (err) {
return next(err);
}
uid = parseInt(uid, 10);
if (uids.indexOf(uid) === -1) {
uids.push(uid);
}
count++;
next();
});
}, next);
},
function (next) {
async.parallel({ async.parallel({
"users": function (next) { users: function (next) {
user.getUsersWithFields(uids, ['uid', 'username', 'userslug', 'picture'], callerUid, next); user.getUsersWithFields(uids, ['uid', 'username', 'userslug', 'picture'], callerUid, next);
}, },
"timestampISO": function (next) { timestampISO: function (next) {
posts.getPostField(replyPids[0], 'timestamp', function (err, timestamp) { posts.getPostField(replyPids[replyPids.length - 1], 'timestamp', next);
next(err, utils.toISOString(timestamp));
});
}
}, function (err, replies) {
if (replies.users.length > 5) {
replies.users.shift();
replies.hasMore = true;
} }
}, next);
},
function (replies, next) {
if (replies.users.length > 5) {
replies.users.shift();
replies.hasMore = true;
}
replies.count = replyPids.length; replies.count = replyPids.length;
replies.timestampISO = utils.toISOString(replies.timestampISO);
next(err, replies); next(null, replies);
}); }
}); ], next);
});
}, callback); }, callback);
} }
}; };

Loading…
Cancel
Save