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) {
async.map(pids, function (pid, next) {
db.getSortedSetRange('pid:' + pid + ':replies', 0, -1, function (err, replyPids) {
var uids = [], count = 0;
var uids = [];
var count = 0;
var replyPids;
async.map(pids, function (pid, _next) {
async.waterfall([
function (next) {
db.getSortedSetRange('pid:' + pid + ':replies', 0, -1, next);
},
function (_replyPids, next) {
replyPids = _replyPids;
if (!replyPids.length) {
return _next(null, {count: 0});
}
async.until(function () {
return count === replyPids.length || uids.length === 6;
}, 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(err);
next();
});
}, function (err) {
}, next);
},
function (next) {
async.parallel({
"users": function (next) {
users: function (next) {
user.getUsersWithFields(uids, ['uid', 'username', 'userslug', 'picture'], callerUid, next);
},
"timestampISO": function (next) {
posts.getPostField(replyPids[0], 'timestamp', function (err, timestamp) {
next(err, utils.toISOString(timestamp));
});
timestampISO: function (next) {
posts.getPostField(replyPids[replyPids.length - 1], 'timestamp', next);
}
}, function (err, replies) {
}, next);
},
function (replies, next) {
if (replies.users.length > 5) {
replies.users.shift();
replies.hasMore = true;
}
replies.count = replyPids.length;
replies.timestampISO = utils.toISOString(replies.timestampISO);
next(err, replies);
});
});
});
next(null, replies);
}
], next);
}, callback);
}
};

Loading…
Cancel
Save