mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 12:56:34 +02:00
replies change
This commit is contained in:
@@ -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;
|
||||
|
||||
async.until(function () {
|
||||
return count === replyPids.length || uids.length === 6;
|
||||
}, function (next) {
|
||||
posts.getPostField(replyPids[count], 'uid', function (err, uid) {
|
||||
uid = parseInt(uid, 10);
|
||||
if (uids.indexOf(uid) === -1) {
|
||||
uids.push(uid);
|
||||
}
|
||||
count++;
|
||||
next(err);
|
||||
});
|
||||
}, function (err) {
|
||||
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();
|
||||
});
|
||||
}, 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));
|
||||
});
|
||||
}
|
||||
}, function (err, replies) {
|
||||
if (replies.users.length > 5) {
|
||||
replies.users.shift();
|
||||
replies.hasMore = true;
|
||||
timestampISO: function (next) {
|
||||
posts.getPostField(replyPids[replyPids.length - 1], 'timestamp', next);
|
||||
}
|
||||
}, 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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user