diff --git a/isso/js/embed.js b/isso/js/embed.js index 6c7c0c61..1c1cfb8e 100644 --- a/isso/js/embed.js +++ b/isso/js/embed.js @@ -139,7 +139,6 @@ function fetchComments() { if (comment.created > lastcreated) { lastcreated = comment.created; } - count = count + comment.total_replies; }); heading.textContent = i18n.pluralize("num-comments", count); diff --git a/isso/tests/test_comments.py b/isso/tests/test_comments.py index ed4b8655..fb2b16a8 100644 --- a/isso/tests/test_comments.py +++ b/isso/tests/test_comments.py @@ -100,6 +100,8 @@ def testCreateAndGetMultiple(self): rv = loads(r.data) self.assertEqual(len(rv['replies']), 20) + self.assertEqual(rv['total_replies'], 20) + def testCreateInvalidParent(self): @@ -185,15 +187,18 @@ def testGetInvalid(self): self.assertEqual(self.get('/?uri=%2Fpath%2F&id=123').status_code, 200) data = loads(self.get('/?uri=%2Fpath%2F&id=123').data) self.assertEqual(len(data['replies']), 0) + self.assertEqual(data['total_replies'], 0) self.assertEqual( self.get('/?uri=%2Fpath%2Fspam%2F&id=123').status_code, 200) data = loads(self.get('/?uri=%2Fpath%2Fspam%2F&id=123').data) self.assertEqual(len(data['replies']), 0) + self.assertEqual(data['total_replies'], 0) self.assertEqual(self.get('/?uri=?uri=%foo%2F').status_code, 200) data = loads(self.get('/?uri=?uri=%foo%2F').data) self.assertEqual(len(data['replies']), 0) + self.assertEqual(data['total_replies'], 0) def testFetchEmpty(self): @@ -214,6 +219,7 @@ def testGetLimited(self): rv = loads(r.data) self.assertEqual(len(rv['replies']), 10) + self.assertEqual(rv['total_replies'], 20) def testGetNested(self): @@ -226,6 +232,7 @@ def testGetNested(self): rv = loads(r.data) self.assertEqual(len(rv['replies']), 1) + self.assertEqual(rv['total_replies'], 1) def testGetLimitedNested(self): @@ -239,6 +246,7 @@ def testGetLimitedNested(self): rv = loads(r.data) self.assertEqual(len(rv['replies']), 10) + self.assertEqual(rv['total_replies'], 20) def testUpdate(self): @@ -289,7 +297,7 @@ def testDeleteWithReference(self): self.assertIn('/path/', self.app.db.threads) data = loads(client.get("/?uri=%2Fpath%2F").data) - self.assertEqual(data["total_replies"], 1) + self.assertEqual(data["total_replies"], 2) self.assertEqual(self.get('/?uri=%2Fpath%2F&id=1').status_code, 200) self.assertEqual(self.get('/?uri=%2Fpath%2F&id=2').status_code, 200) diff --git a/isso/views/comments.py b/isso/views/comments.py index 3fd2d342..5cecd499 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -880,6 +880,9 @@ def fetch(self, environ, request, uri): if root_id not in reply_counts: reply_counts[root_id] = 0 + # We need to calculate the total number of comments for the root response value + total_replies = sum(reply_counts.values()) if root_id is None else reply_counts[root_id] + try: nested_limit = int(request.args.get('nested_limit')) except TypeError: @@ -889,7 +892,7 @@ def fetch(self, environ, request, uri): rv = { 'id': root_id, - 'total_replies': reply_counts[root_id], + 'total_replies': total_replies, 'hidden_replies': reply_counts[root_id] - len(root_list), 'replies': self._process_fetched_list(root_list, plain), 'config': self.public_conf