Skip to content

Node.js based forum software built for the modern web

replies/reply fix

Barış Soner Uşaklı29ca1dbf0883
diff --git a/public/language/en-GB/topic.json b/public/language/en-GB/topic.json
index b960fb0fba..727417ca5f 100644
--- a/public/language/en-GB/topic.json
+++ b/public/language/en-GB/topic.json
@@ -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",
diff --git a/public/src/client/topic/replies.js b/public/src/client/topic/replies.js
index 7d9b9474bc..37ddd1912b 100644
--- a/public/src/client/topic/replies.js
+++ b/public/src/client/topic/replies.js
@@ -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);
- countEl.translateText('[[topic:replies_to_this_post, ' + 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();
diff --git a/src/topics/posts.js b/src/topics/posts.js
index ce2b6dd457..3ed8deafc7 100644
--- a/src/topics/posts.js
+++ b/src/topics/posts.js
@@ -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 uids = [];
- var 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 += 1;
- next(err);
- });
- }, function (err) {
- 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) {
+ 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();
+ },
+ ], 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) {
- if (replies.users.length > 5) {
- replies.users.shift();
- replies.hasMore = true;
- }
+ }, next);
+ },
+ function (replies, next) {
+ if (replies.users.length > 5) {
+ replies.users.shift();
+ replies.hasMore = true;
+ }
- replies.count = replyPids.length;
- next(err, replies);
- });
- });
- });
+ replies.count = replyPids.length;
+ replies.text = replies.count > 1 ? '[[topic:replies_to_this_post, ' + replies.count + ']]' : '[[topic:one_reply_to_this_post]]';
+ next(null, replies);
+ },
+ ], next);
}, callback);
}
};