replies/reply fix

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

@ -17,6 +17,7 @@
"quote": "Quote",
"reply": "Reply",
"replies_to_this_post": "%1 Replies",
"one_reply_to_this_post": "1 Reply",
"last_reply_time": "Last reply",
"reply-as-topic": "Reply as topic",
"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);
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 + ']]');
} 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');
timestamp.data('timeago', null).timeago();

@ -392,30 +392,36 @@ 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) {
if (err) {
return next(err);
}
var replyPids;
var uids = [];
async.waterfall([
function (next) {
db.getSortedSetRange('pid:' + pid + ':replies', 0, -1, next);
},
function (_replyPids, next) {
replyPids = _replyPids;
var count = 0;
async.until(function () {
return count === replyPids.length || uids.length === 6;
}, 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);
if (uids.indexOf(uid) === -1) {
uids.push(uid);
}
count += 1;
next(err);
});
}, function (err) {
if (err) {
return next(err);
}
next();
},
], next);
}, next);
},
function (next) {
async.parallel({
users: function (next) {
user.getUsersWithFields(uids, ['uid', 'username', 'userslug', 'picture'], callerUid, next);
@ -425,17 +431,19 @@ module.exports = function (Topics) {
next(err, utils.toISOString(timestamp));
});
},
}, function (err, replies) {
}, next);
},
function (replies, next) {
if (replies.users.length > 5) {
replies.users.shift();
replies.hasMore = true;
}
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);
}
};

Loading…
Cancel
Save