replies/reply fix

v1.18.x
Barış Soner Uşaklı 8 years ago
parent 8f8e7202e5
commit 29ca1dbf08

@ -17,6 +17,7 @@
"quote": "Quote", "quote": "Quote",
"reply": "Reply", "reply": "Reply",
"replies_to_this_post": "%1 Replies", "replies_to_this_post": "%1 Replies",
"one_reply_to_this_post": "1 Reply",
"last_reply_time": "Last reply", "last_reply_time": "Last reply",
"reply-as-topic": "Reply as topic", "reply-as-topic": "Reply as topic",
"guest-login-reply": "Log in to reply", "guest-login-reply": "Log in to reply",

@ -89,8 +89,19 @@ define('forum/topic/replies', ['navigator', 'components', 'forum/topic/posts'],
var timestamp = replyCount.find('.timeago').attr('title', post.timestampISO); var timestamp = replyCount.find('.timeago').attr('title', post.timestampISO);
countEl.attr('data-replies', count); countEl.attr('data-replies', count);
replyCount.toggleClass('hidden', !count); replyCount.toggleClass('hidden', count <= 0);
if (count > 1) {
countEl.translateText('[[topic:replies_to_this_post, ' + count + ']]'); countEl.translateText('[[topic:replies_to_this_post, ' + count + ']]');
} else {
countEl.translateText('[[topic:one_reply_to_this_post]]');
}
if (!avatars.find('[data-uid="' + post.uid + '"]').length && count < 7) {
app.parseAndTranslate('topic', 'posts', { posts: [{ replies: { users: [post.user] } }] }, function (html) {
avatars.prepend(html.find('[component="post/reply-count/avatars"] [component="user/picture"]'));
});
}
avatars.addClass('hasMore'); avatars.addClass('hasMore');
timestamp.data('timeago', null).timeago(); timestamp.data('timeago', null).timeago();

@ -392,30 +392,36 @@ module.exports = function (Topics) {
function getPostReplies(pids, callerUid, callback) { function getPostReplies(pids, callerUid, callback) {
async.map(pids, function (pid, next) { async.map(pids, function (pid, next) {
db.getSortedSetRange('pid:' + pid + ':replies', 0, -1, function (err, replyPids) { var replyPids;
if (err) {
return next(err);
}
var uids = []; var uids = [];
async.waterfall([
function (next) {
db.getSortedSetRange('pid:' + pid + ':replies', 0, -1, next);
},
function (_replyPids, next) {
replyPids = _replyPids;
var count = 0; var count = 0;
async.until(function () { async.until(function () {
return count === replyPids.length || uids.length === 6; return count === replyPids.length || uids.length === 6;
}, function (next) { }, function (next) {
posts.getPostField(replyPids[count], 'uid', function (err, uid) { async.waterfall([
function (next) {
posts.getPostField(replyPids[count], 'uid', next);
},
function (uid, next) {
uid = parseInt(uid, 10); uid = parseInt(uid, 10);
if (uids.indexOf(uid) === -1) { if (uids.indexOf(uid) === -1) {
uids.push(uid); uids.push(uid);
} }
count += 1; count += 1;
next(err); next();
}); },
}, function (err) { ], next);
if (err) { }, next);
return next(err); },
} 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);
@ -425,17 +431,19 @@ module.exports = function (Topics) {
next(err, utils.toISOString(timestamp)); next(err, utils.toISOString(timestamp));
}); });
}, },
}, function (err, replies) { }, next);
},
function (replies, next) {
if (replies.users.length > 5) { if (replies.users.length > 5) {
replies.users.shift(); replies.users.shift();
replies.hasMore = true; replies.hasMore = true;
} }
replies.count = replyPids.length; replies.count = replyPids.length;
next(err, replies); replies.text = replies.count > 1 ? '[[topic:replies_to_this_post, ' + replies.count + ']]' : '[[topic:one_reply_to_this_post]]';
}); next(null, replies);
}); },
}); ], next);
}, callback); }, callback);
} }
}; };

Loading…
Cancel
Save