diff --git a/public/language/en-GB/topic.json b/public/language/en-GB/topic.json index 29a85c15cc..933a829fa7 100644 --- a/public/language/en-GB/topic.json +++ b/public/language/en-GB/topic.json @@ -16,7 +16,8 @@ "notify_me": "Be notified of new replies in this topic", "quote": "Quote", "reply": "Reply", - "replies_to_this_post": "Replies: %1", + "replies_to_this_post": "%1 Replies", + "last_reply_time": "Last reply", "reply-as-topic": "Reply as topic", "guest-login-reply": "Log in to reply", "edit": "Edit", diff --git a/public/src/client/topic/replies.js b/public/src/client/topic/replies.js index ba7fd81f33..d025091d1e 100644 --- a/public/src/client/topic/replies.js +++ b/public/src/client/topic/replies.js @@ -21,9 +21,9 @@ define('forum/topic/replies', ['navigator', 'components', 'forum/topic/posts'], function onRepliesClicked(button, tid) { var post = button.closest('[data-pid]'); var pid = post.data('pid'); - var open = button.children('[component="post/replies/open"]'); - var loading = button.children('[component="post/replies/loading"]'); - var close = button.children('[component="post/replies/close"]'); + var open = button.find('[component="post/replies/open"]'); + var loading = button.find('[component="post/replies/loading"]'); + var close = button.find('[component="post/replies/close"]'); if (open.is(':not(.hidden)') && loading.is('.hidden')) { open.addClass('hidden'); @@ -86,10 +86,12 @@ define('forum/topic/replies', ['navigator', 'components', 'forum/topic/posts'], function incrementCount(post, inc) { var replyCount = $('[component="post"][data-pid="' + post.toPid + '"]').find('[component="post/reply-count"]').first(); var countEl = replyCount.find('[component="post/reply-count/text"]'); + var avatars = replyCount.find('[component="post/reply-count/avatars"]'); var count = Math.max(0, parseInt(countEl.attr('data-replies'), 10) + inc); countEl.attr('data-replies', count); replyCount.toggleClass('hidden', !count); countEl.translateText('[[topic:replies_to_this_post, ' + count + ']]'); + avatars.addClass('hasMore'); } return Replies; diff --git a/src/topics/posts.js b/src/topics/posts.js index aadf6bd76b..7f936b9b0d 100644 --- a/src/topics/posts.js +++ b/src/topics/posts.js @@ -10,6 +10,7 @@ var user = require('../user'); var posts = require('../posts'); var meta = require('../meta'); var plugins = require('../plugins'); +var utils = require('../../public/src/utils'); module.exports = function (Topics) { @@ -109,6 +110,9 @@ module.exports = function (Topics) { }, parents: function (next) { Topics.addParentPosts(postData, next); + }, + replies: function (next) { + getPostReplies(pids, uid, next); } }, function (err, results) { if (err) { @@ -123,8 +127,8 @@ module.exports = function (Topics) { postObj.bookmarked = results.bookmarks[i]; postObj.upvoted = results.voteData.upvotes[i]; postObj.downvoted = results.voteData.downvotes[i]; + postObj.replies = results.replies[i]; postObj.votes = postObj.votes || 0; - postObj.replies = postObj.replies || 0; postObj.selfPost = !!parseInt(uid, 10) && parseInt(uid, 10) === parseInt(postObj.uid, 10); // Username override for guests, if enabled @@ -384,4 +388,45 @@ module.exports = function (Topics) { db.getObjectField('topic:' + tid, 'postcount', callback); }; + 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) { + async.parallel({ + "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)); + }); + }, + "count": function (next) { + db.sortedSetCard('pid:' + pid + ':replies', next); + } + }, function (err, replies) { + if (replies.users.length > 5) { + replies.users.shift(); + replies.hasMore = true; + } + + next(err, replies); + }); + }); + }); + }, callback); + } };