From 71024cea708a6a794aa876017ac08431c97a07d1 Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Sun, 20 Apr 2014 18:46:43 +0530 Subject: [PATCH 01/20] API update - new comments format --- isso/db/comments.py | 37 +++++++++++++++++++++++++---- isso/views/comments.py | 54 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 80 insertions(+), 11 deletions(-) diff --git a/isso/db/comments.py b/isso/db/comments.py index 8c97121..9c3bdda 100644 --- a/isso/db/comments.py +++ b/isso/db/comments.py @@ -97,15 +97,31 @@ class Comments: return None - def fetch(self, uri, mode=5): + def fetch(self, uri, mode=5, after=0, parent='any', order_by='id', limit=None): """ Return comments for :param:`uri` with :param:`mode`. """ - rv = self.db.execute([ - 'SELECT comments.* FROM comments INNER JOIN threads ON', - ' threads.uri=? AND comments.tid=threads.id AND (? | comments.mode) = ?' - 'ORDER BY id ASC;'], (uri, mode, mode)).fetchall() + sql = [ 'SELECT comments.* FROM comments INNER JOIN threads ON', + ' threads.uri=? AND comments.tid=threads.id AND (? | comments.mode) = ?', + ' AND comments.created>?'] + sql_args = [uri, mode, mode, after] + + if parent != 'any': + if parent is None or parent == 'NULL': + sql.append('AND comments.parent IS NULL') + else: + sql.append('AND comments.parent=?') + sql_args.append(parent) + + sql.append('ORDER BY ? ASC') + sql_args.append(order_by) + + if limit != None and limit != 0: + sql.append('LIMIT ?') + sql_args.append(limit) + + rv = self.db.execute(sql, sql_args).fetchall() for item in rv: yield dict(zip(Comments.fields, item)) @@ -181,6 +197,17 @@ class Comments: return {'likes': likes + 1, 'dislikes': dislikes} return {'likes': likes, 'dislikes': dislikes + 1} + def reply_count(self, url): + """ + Return comment count for main thread and all reply threads for one url. + """ + + sql = [ 'SELECT comments.parent,count(*) FROM comments INNER JOIN threads ON', + ' threads.uri=? AND comments.tid=threads.id', + ' AND comments.mode = 1 group by comments.parent;'] + + return dict(self.db.execute(sql, [url]).fetchall()) + def count(self, *urls): """ Return comment count for one ore more urls.. diff --git a/isso/views/comments.py b/isso/views/comments.py index eac16ff..40958d1 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -320,11 +320,53 @@ class API(object): @requires(str, 'uri') def fetch(self, environ, request, uri): - rv = list(self.comments.fetch(uri)) - if not rv: + fetch_args={'uri': uri} + if request.args.get('after'): + fetch_args['after'] = request.args.get('after') + if request.args.get('limit'): + try: + fetch_args['limit'] = int(request.args.get('limit')) + except ValueError: + return BadRequest("Limit should be integer") + if request.args.get('parent'): + try: + fetch_args['parent'] = int(request.args.get('parent')) + root_id = int(request.args.get('parent')) + except ValueError: + return BadRequest("Parent should be integer") + else: + root_id = None + + if request.args.get('plain', '0') == '0': + plain = True + else: + plain = False + + reply_counts = self.comments.reply_count(uri) + + full_list = list(self.comments.fetch(**fetch_args)) + root_list = [i for i in full_list if i['parent'] == root_id] + if not root_list: raise NotFound - for item in rv: + rv = { + 'id' : root_id, + 'passed_replies' : len(root_list), + 'total_replies' : reply_counts[root_id], + 'replies' : self.process_fetched_list(root_list, plain) + } + # We are only checking for one level deep comments + if root_id is None: + for comment in rv['replies']: + replies = [i for i in full_list if i['parent'] == comment['id']] + comment['passed_replies'] = len(replies) + comment['total_replies'] = reply_counts[comment['id']] + comment['replies'] = self.process_fetched_list(replies, plain) + + return JSON(rv, 200) + + def process_fetched_list(self, fetched_list, plain=False): + for item in fetched_list: key = item['email'] or item['remote_addr'] val = self.cache.get('hash', key.encode('utf-8')) @@ -338,11 +380,11 @@ class API(object): for key in set(item.keys()) - API.FIELDS: item.pop(key) - if request.args.get('plain', '0') == '0': - for item in rv: + if plain: + for item in fetched_list: item['text'] = self.isso.render(item['text']) - return JSON(rv, 200) + return fetched_list @xhr def like(self, environ, request, id): From 8fdceeaafb32739920e65a3ce44792a9ae56a7fb Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Sun, 20 Apr 2014 19:27:49 +0530 Subject: [PATCH 02/20] Handle edge cases occuring in tests --- isso/tests/test_comments.py | 2 +- isso/views/comments.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/isso/tests/test_comments.py b/isso/tests/test_comments.py index 5124743..6ba8ec5 100644 --- a/isso/tests/test_comments.py +++ b/isso/tests/test_comments.py @@ -103,7 +103,7 @@ class TestComments(unittest.TestCase): self.assertEqual(r.status_code, 200) rv = loads(r.data) - self.assertEqual(len(rv), 20) + self.assertEqual(len(rv['replies']), 20) def testCreateInvalidParent(self): diff --git a/isso/views/comments.py b/isso/views/comments.py index 40958d1..608b436 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -348,6 +348,8 @@ class API(object): root_list = [i for i in full_list if i['parent'] == root_id] if not root_list: raise NotFound + if root_id not in reply_counts: + reply_counts[root_id] = 0 rv = { 'id' : root_id, @@ -360,8 +362,11 @@ class API(object): for comment in rv['replies']: replies = [i for i in full_list if i['parent'] == comment['id']] comment['passed_replies'] = len(replies) - comment['total_replies'] = reply_counts[comment['id']] - comment['replies'] = self.process_fetched_list(replies, plain) + if comment['id'] in reply_counts: + comment['total_replies'] = reply_counts[comment['id']] + else: + comment['total_replies'] = 0 + comment['replies'] = self.process_fetched_list(replies, plain) return JSON(rv, 200) From 3c3e83b05ce2102efc6846c2ba91c383f38b272d Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Wed, 23 Apr 2014 00:56:40 +0530 Subject: [PATCH 03/20] Bug in API: Reply count should also filter by the after value passed --- isso/db/comments.py | 6 +++--- isso/views/comments.py | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/isso/db/comments.py b/isso/db/comments.py index 9c3bdda..c88947a 100644 --- a/isso/db/comments.py +++ b/isso/db/comments.py @@ -197,16 +197,16 @@ class Comments: return {'likes': likes + 1, 'dislikes': dislikes} return {'likes': likes, 'dislikes': dislikes + 1} - def reply_count(self, url): + def reply_count(self, url, after=0): """ Return comment count for main thread and all reply threads for one url. """ sql = [ 'SELECT comments.parent,count(*) FROM comments INNER JOIN threads ON', ' threads.uri=? AND comments.tid=threads.id', - ' AND comments.mode = 1 group by comments.parent;'] + ' AND comments.mode = 1 AND comments.created>? GROUP BY comments.parent;'] - return dict(self.db.execute(sql, [url]).fetchall()) + return dict(self.db.execute(sql, [url, after]).fetchall()) def count(self, *urls): """ diff --git a/isso/views/comments.py b/isso/views/comments.py index 608b436..658b381 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -323,6 +323,9 @@ class API(object): fetch_args={'uri': uri} if request.args.get('after'): fetch_args['after'] = request.args.get('after') + after = request.args.get('after') + else: + after = 0 if request.args.get('limit'): try: fetch_args['limit'] = int(request.args.get('limit')) @@ -342,7 +345,7 @@ class API(object): else: plain = False - reply_counts = self.comments.reply_count(uri) + reply_counts = self.comments.reply_count(uri, after) full_list = list(self.comments.fetch(**fetch_args)) root_list = [i for i in full_list if i['parent'] == root_id] From a5d8a0cfe1fc762fdced5a1fbe9863139334edab Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Wed, 23 Apr 2014 00:57:31 +0530 Subject: [PATCH 04/20] Change in API: hidden_replies field instead of passed_replies --- isso/views/comments.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/isso/views/comments.py b/isso/views/comments.py index 658b381..52d72e6 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -356,19 +356,19 @@ class API(object): rv = { 'id' : root_id, - 'passed_replies' : len(root_list), 'total_replies' : reply_counts[root_id], + 'hidden_replies' : reply_counts[root_id] - len(root_list), 'replies' : self.process_fetched_list(root_list, plain) } # We are only checking for one level deep comments if root_id is None: for comment in rv['replies']: replies = [i for i in full_list if i['parent'] == comment['id']] - comment['passed_replies'] = len(replies) if comment['id'] in reply_counts: comment['total_replies'] = reply_counts[comment['id']] else: comment['total_replies'] = 0 + comment['hidden_replies'] = comment['total_replies'] - len(replies) comment['replies'] = self.process_fetched_list(replies, plain) return JSON(rv, 200) From 8dbf4d53375f5bee6b1521183182438abd6954c1 Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Wed, 23 Apr 2014 01:15:16 +0530 Subject: [PATCH 05/20] Client side changes for new API * Handle hierarchal comments data format * New comments fetching parameters: limit, parent, after * Link to load more comments --- isso/js/app/api.js | 8 ++-- isso/js/app/isso.js | 64 +++++++++++++++++++++++++++- isso/js/app/text/comment-loader.html | 3 ++ isso/js/app/text/html.js | 5 ++- isso/js/embed.js | 18 +++++--- 5 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 isso/js/app/text/comment-loader.html diff --git a/isso/js/app/api.js b/isso/js/app/api.js index 73c2a88..247cfd7 100644 --- a/isso/js/app/api.js +++ b/isso/js/app/api.js @@ -128,13 +128,15 @@ define(["app/lib/promise", "app/globals"], function(Q, globals) { return deferred.promise; }; - var fetch = function(tid) { + var fetch = function(tid, limit, parent, lastcreated) { + if(typeof(limit) == 'undefined') limit = 0; + if(typeof(parent) == 'undefined') parent = null; var deferred = Q.defer(); - curl("GET", endpoint + "/?" + qs({uri: tid || location}), null, function(rv) { + curl("GET", endpoint + "/?" + qs({uri: tid || location, limit: limit, parent: parent, after: lastcreated}), null, function(rv) { if (rv.status === 200) { deferred.resolve(JSON.parse(rv.body)); } else if (rv.status === 404) { - deferred.resolve([]); + deferred.resolve({total_replies: 0}); } else { deferred.reject(rv.body); } diff --git a/isso/js/app/isso.js b/isso/js/app/isso.js index e903b6a..fc0cbdf 100644 --- a/isso/js/app/isso.js +++ b/isso/js/app/isso.js @@ -84,8 +84,51 @@ define(["app/text/html", "app/dom", "app/utils", "app/config", "app/api", "app/m return el; }; - var insert = function(comment, scrollIntoView) { + var insert_loader = function(commentWrapper, lastcreated) { + var entrypoint; + if (commentWrapper.id === null) { + entrypoint = $("#isso-root"); + commentWrapper.name = 'null'; + } else { + entrypoint = $("#isso-" + commentWrapper.id + " > .text-wrapper > .isso-follow-up"); + commentWrapper.name = commentWrapper.id; + } + var el = $.htmlify(Mark.up(templates["comment_loader"], commentWrapper)); + entrypoint.append(el); + + $("a.load_hidden", el).toggle("click", + function() { + el.remove(); + api.fetch($("#isso-thread").getAttribute("data-isso-id"), limit=20, parent=commentWrapper.id, lastcreated=lastcreated).then( + function(rv) { + if (rv.total_replies == 0) { + return; + } + + var lastcreated = 0; + rv.replies.forEach(function(commentObject) { + insert(commentObject, false); + if(commentObject.created > lastcreated) { + lastcreated = commentObject.created; + } + }); + + if(rv.hidden_replies > 0) { + insert_loader(rv, lastcreated); + } + + if (window.location.hash.length > 0) { + $(window.location.hash).scrollIntoView(); + } + }, + function(err) { + console.log(err); + }); + }); + }; + + var insert = function(comment, scrollIntoView) { var el = $.htmlify(Mark.up(templates["comment"], comment)); // update datetime every 60 seconds @@ -132,7 +175,7 @@ define(["app/text/html", "app/dom", "app/utils", "app/config", "app/api", "app/m ); // update vote counter, but hide if votes sum to 0 - var votes = function(value) { + var votes = function(value) { var span = $("span.votes", footer); if (span === null && value !== 0) { footer.prepend($.new("span.votes", value)); @@ -261,10 +304,27 @@ define(["app/text/html", "app/dom", "app/utils", "app/config", "app/api", "app/m if (! config["reply-to-self"] && utils.cookie("isso-" + comment.id)) { show($("a.reply", footer).detach()); } + + if(comment.hasOwnProperty('replies')) { + var lastcreated = 0; + comment.replies.forEach(function(replyObject) { + insert(replyObject, false); + if(replyObject.created > lastcreated) { + lastcreated = replyObject.created; + } + + }); + if(comment.hidden_replies > 0) { + insert_loader(comment, lastcreated); + } + + } + }; return { insert: insert, + insert_loader: insert_loader, Postbox: Postbox }; }); diff --git a/isso/js/app/text/comment-loader.html b/isso/js/app/text/comment-loader.html new file mode 100644 index 0000000..f6e7bad --- /dev/null +++ b/isso/js/app/text/comment-loader.html @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/isso/js/app/text/html.js b/isso/js/app/text/html.js index eed9515..cf2c865 100644 --- a/isso/js/app/text/html.js +++ b/isso/js/app/text/html.js @@ -1,6 +1,7 @@ -define(["text!./postbox.html", "text!./comment.html"], function (postbox, comment) { +define(["text!./postbox.html", "text!./comment.html", "text!./comment-loader.html"], function (postbox, comment, comment_loader) { return { postbox: postbox, - comment: comment + comment: comment, + comment_loader: comment_loader }; }); diff --git a/isso/js/embed.js b/isso/js/embed.js index 6c6fbfc..44fdfb5 100644 --- a/isso/js/embed.js +++ b/isso/js/embed.js @@ -26,16 +26,24 @@ require(["app/lib/ready", "app/config", "app/api", "app/isso", "app/count", "app $("#isso-thread").append(new isso.Postbox(null)); $("#isso-thread").append('
'); - api.fetch($("#isso-thread").getAttribute("data-isso-id")).then( + api.fetch($("#isso-thread").getAttribute("data-isso-id"), limit=20).then( function(rv) { - if (! rv.length) { + if (rv.total_replies == 0) { $("#isso-thread > h4").textContent = Mark.up("{{ i18n-no-comments }}"); return; } - $("#isso-thread > h4").textContent = Mark.up("{{ i18n-num-comments | pluralize : `n` }}", {n: rv.length}); - for (var i=0; i < rv.length; i++) { - isso.insert(rv[i], false); + $("#isso-thread > h4").textContent = Mark.up("{{ i18n-num-comments | pluralize : `n` }}", {n: rv.total_replies}); + var lastcreated = 0; + rv.replies.forEach(function(commentObject) { + isso.insert(commentObject, false); + if(commentObject.created > lastcreated) { + lastcreated = commentObject.created; + } + }); + + if(rv.hidden_replies > 0) { + isso.insert_loader(rv, lastcreated); } if (window.location.hash.length > 0) { From 76d5dbc97fed506293773e4ba9ee37e1ee2ad88d Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Fri, 25 Apr 2014 01:07:40 +0530 Subject: [PATCH 06/20] Take max comments to load from config.js --- isso/js/app/config.js | 1 + isso/js/app/isso.js | 2 +- isso/js/embed.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/isso/js/app/config.js b/isso/js/app/config.js index 3ebc5c7..a2cc767 100644 --- a/isso/js/app/config.js +++ b/isso/js/app/config.js @@ -5,6 +5,7 @@ define(function() { "css": true, "lang": (navigator.language || navigator.userLanguage).split("-")[0], "reply-to-self": false, + "max-comments": 20, "avatar-bg": "#f0f0f0", "avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6", "#be5168", "#f19670", "#e4bf80", "#447c69"].join(" ") diff --git a/isso/js/app/isso.js b/isso/js/app/isso.js index fc0cbdf..90c28af 100644 --- a/isso/js/app/isso.js +++ b/isso/js/app/isso.js @@ -100,7 +100,7 @@ define(["app/text/html", "app/dom", "app/utils", "app/config", "app/api", "app/m $("a.load_hidden", el).toggle("click", function() { el.remove(); - api.fetch($("#isso-thread").getAttribute("data-isso-id"), limit=20, parent=commentWrapper.id, lastcreated=lastcreated).then( + api.fetch($("#isso-thread").getAttribute("data-isso-id"), limit = config["max-comments"], parent=commentWrapper.id, lastcreated=lastcreated).then( function(rv) { if (rv.total_replies == 0) { return; diff --git a/isso/js/embed.js b/isso/js/embed.js index 44fdfb5..a840592 100644 --- a/isso/js/embed.js +++ b/isso/js/embed.js @@ -26,7 +26,7 @@ require(["app/lib/ready", "app/config", "app/api", "app/isso", "app/count", "app $("#isso-thread").append(new isso.Postbox(null)); $("#isso-thread").append('
'); - api.fetch($("#isso-thread").getAttribute("data-isso-id"), limit=20).then( + api.fetch($("#isso-thread").getAttribute("data-isso-id"), limit = config["max-comments"]).then( function(rv) { if (rv.total_replies == 0) { $("#isso-thread > h4").textContent = Mark.up("{{ i18n-no-comments }}"); From f5da45e52503d47258ba1b61f4c438bfb2166a5b Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Sat, 26 Apr 2014 22:54:55 +0530 Subject: [PATCH 07/20] Correct total comments count --- isso/js/embed.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/isso/js/embed.js b/isso/js/embed.js index a840592..11a807a 100644 --- a/isso/js/embed.js +++ b/isso/js/embed.js @@ -33,14 +33,16 @@ require(["app/lib/ready", "app/config", "app/api", "app/isso", "app/count", "app return; } - $("#isso-thread > h4").textContent = Mark.up("{{ i18n-num-comments | pluralize : `n` }}", {n: rv.total_replies}); var lastcreated = 0; + var total_count = rv.total_replies; rv.replies.forEach(function(commentObject) { isso.insert(commentObject, false); if(commentObject.created > lastcreated) { lastcreated = commentObject.created; } + total_count = total_count + commentObject.total_replies; }); + $("#isso-thread > h4").textContent = Mark.up("{{ i18n-num-comments | pluralize : `n` }}", {n: total_count}); if(rv.hidden_replies > 0) { isso.insert_loader(rv, lastcreated); From 54b156844b9fe291468cd7b2eea79c98c5908e99 Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Sun, 27 Apr 2014 11:44:18 +0530 Subject: [PATCH 08/20] Add max-comments limit for nested replies --- isso/js/app/api.js | 22 ++++++++++++---------- isso/js/app/config.js | 3 ++- isso/js/app/isso.js | 5 ++++- isso/js/embed.js | 5 ++++- isso/views/comments.py | 37 ++++++++++++++++++++++++++++--------- 5 files changed, 50 insertions(+), 22 deletions(-) diff --git a/isso/js/app/api.js b/isso/js/app/api.js index 247cfd7..2c5eba5 100644 --- a/isso/js/app/api.js +++ b/isso/js/app/api.js @@ -128,19 +128,21 @@ define(["app/lib/promise", "app/globals"], function(Q, globals) { return deferred.promise; }; - var fetch = function(tid, limit, parent, lastcreated) { + var fetch = function(tid, limit, nested_limit, parent, lastcreated) { if(typeof(limit) == 'undefined') limit = 0; + if(typeof(nested_limit) == 'undefined') nested_limit = 0; if(typeof(parent) == 'undefined') parent = null; var deferred = Q.defer(); - curl("GET", endpoint + "/?" + qs({uri: tid || location, limit: limit, parent: parent, after: lastcreated}), null, function(rv) { - if (rv.status === 200) { - deferred.resolve(JSON.parse(rv.body)); - } else if (rv.status === 404) { - deferred.resolve({total_replies: 0}); - } else { - deferred.reject(rv.body); - } - }); + curl("GET", endpoint + "/?" + + qs({uri: tid || location, limit: limit, nested_limit: nested_limit, after: lastcreated, parent: parent}), null, function(rv) { + if (rv.status === 200) { + deferred.resolve(JSON.parse(rv.body)); + } else if (rv.status === 404) { + deferred.resolve({total_replies: 0}); + } else { + deferred.reject(rv.body); + } + }); return deferred.promise; }; diff --git a/isso/js/app/config.js b/isso/js/app/config.js index a2cc767..d9fa133 100644 --- a/isso/js/app/config.js +++ b/isso/js/app/config.js @@ -5,7 +5,8 @@ define(function() { "css": true, "lang": (navigator.language || navigator.userLanguage).split("-")[0], "reply-to-self": false, - "max-comments": 20, + "max-comments-top": 20, + "max-comments-nested": 5, "avatar-bg": "#f0f0f0", "avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6", "#be5168", "#f19670", "#e4bf80", "#447c69"].join(" ") diff --git a/isso/js/app/isso.js b/isso/js/app/isso.js index 90c28af..3cc780a 100644 --- a/isso/js/app/isso.js +++ b/isso/js/app/isso.js @@ -100,7 +100,10 @@ define(["app/text/html", "app/dom", "app/utils", "app/config", "app/api", "app/m $("a.load_hidden", el).toggle("click", function() { el.remove(); - api.fetch($("#isso-thread").getAttribute("data-isso-id"), limit = config["max-comments"], parent=commentWrapper.id, lastcreated=lastcreated).then( + api.fetch($("#isso-thread").getAttribute("data-isso-id"), + limit = config["max-comments-top"], nested_limit=0, + parent=commentWrapper.id, + lastcreated=lastcreated).then( function(rv) { if (rv.total_replies == 0) { return; diff --git a/isso/js/embed.js b/isso/js/embed.js index 11a807a..4bdd98a 100644 --- a/isso/js/embed.js +++ b/isso/js/embed.js @@ -26,7 +26,10 @@ require(["app/lib/ready", "app/config", "app/api", "app/isso", "app/count", "app $("#isso-thread").append(new isso.Postbox(null)); $("#isso-thread").append('
'); - api.fetch($("#isso-thread").getAttribute("data-isso-id"), limit = config["max-comments"]).then( + api.fetch($("#isso-thread").getAttribute("data-isso-id"), + limit = config["max-comments-top"], + nested_limit = config["max-comments-nested"], + parent='NULL').then( function(rv) { if (rv.total_replies == 0) { $("#isso-thread > h4").textContent = Mark.up("{{ i18n-no-comments }}"); diff --git a/isso/views/comments.py b/isso/views/comments.py index 52d72e6..f172bcd 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -330,14 +330,20 @@ class API(object): try: fetch_args['limit'] = int(request.args.get('limit')) except ValueError: - return BadRequest("Limit should be integer") + return BadRequest("limit should be integer") if request.args.get('parent'): - try: - fetch_args['parent'] = int(request.args.get('parent')) - root_id = int(request.args.get('parent')) - except ValueError: - return BadRequest("Parent should be integer") + parent_arg = request.args.get('parent') + if parent_arg == 'NULL': + fetch_args['parent'] = parent_arg + root_id = None + else: + try: + fetch_args['parent'] = int(parent_arg) + root_id = int(parent_arg) + except ValueError: + return BadRequest("parent should be integer or NULL") else: + fetch_args['parent'] = 'NULL' root_id = None if request.args.get('plain', '0') == '0': @@ -347,13 +353,20 @@ class API(object): reply_counts = self.comments.reply_count(uri, after) - full_list = list(self.comments.fetch(**fetch_args)) - root_list = [i for i in full_list if i['parent'] == root_id] + root_list = list(self.comments.fetch(**fetch_args)) if not root_list: raise NotFound if root_id not in reply_counts: reply_counts[root_id] = 0 + if request.args.get('nested_limit'): + try: + nested_limit = int(request.args.get('nested_limit')) + except ValueError: + return BadRequest("nested_limit should be integer") + else: + nested_limit = 0 + rv = { 'id' : root_id, 'total_replies' : reply_counts[root_id], @@ -363,11 +376,17 @@ class API(object): # We are only checking for one level deep comments if root_id is None: for comment in rv['replies']: - replies = [i for i in full_list if i['parent'] == comment['id']] if comment['id'] in reply_counts: comment['total_replies'] = reply_counts[comment['id']] + if nested_limit > 0: + fetch_args['parent'] = comment['id'] + fetch_args['limit'] = nested_limit + replies = list(self.comments.fetch(**fetch_args)) + else: + replies = [] else: comment['total_replies'] = 0 + replies = [] comment['hidden_replies'] = comment['total_replies'] - len(replies) comment['replies'] = self.process_fetched_list(replies, plain) From abc0eaaf1d3c02c4723c178b3c58acbf374b1ae6 Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Sat, 3 May 2014 01:14:23 +0530 Subject: [PATCH 09/20] Handle limit/nested_limit zero This returns zero comments now --- isso/views/comments.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/isso/views/comments.py b/isso/views/comments.py index f172bcd..94e4fa7 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -331,6 +331,7 @@ class API(object): fetch_args['limit'] = int(request.args.get('limit')) except ValueError: return BadRequest("limit should be integer") + if request.args.get('parent'): parent_arg = request.args.get('parent') if parent_arg == 'NULL': @@ -353,9 +354,12 @@ class API(object): reply_counts = self.comments.reply_count(uri, after) - root_list = list(self.comments.fetch(**fetch_args)) - if not root_list: - raise NotFound + if 'limit' in fetch_args and fetch_args['limit'] == 0: + root_list = [] + else: + root_list = list(self.comments.fetch(**fetch_args)) + if not root_list: + raise NotFound if root_id not in reply_counts: reply_counts[root_id] = 0 @@ -365,7 +369,7 @@ class API(object): except ValueError: return BadRequest("nested_limit should be integer") else: - nested_limit = 0 + nested_limit = None rv = { 'id' : root_id, @@ -378,12 +382,16 @@ class API(object): for comment in rv['replies']: if comment['id'] in reply_counts: comment['total_replies'] = reply_counts[comment['id']] - if nested_limit > 0: - fetch_args['parent'] = comment['id'] - fetch_args['limit'] = nested_limit - replies = list(self.comments.fetch(**fetch_args)) + if nested_limit is not None: + if nested_limit > 0: + fetch_args['parent'] = comment['id'] + fetch_args['limit'] = nested_limit + replies = list(self.comments.fetch(**fetch_args)) + else: + replies = [] else: - replies = [] + fetch_args['parent'] = comment['id'] + replies = list(self.comments.fetch(**fetch_args)) else: comment['total_replies'] = 0 replies = [] From 2e2fba89a64904c4e40efa948110db7729fa2af0 Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Sat, 3 May 2014 01:14:33 +0530 Subject: [PATCH 10/20] Add some tests --- isso/tests/test_comments.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/isso/tests/test_comments.py b/isso/tests/test_comments.py index 6ba8ec5..17a8b79 100644 --- a/isso/tests/test_comments.py +++ b/isso/tests/test_comments.py @@ -138,6 +138,40 @@ class TestComments(unittest.TestCase): self.assertEqual(self.get('/?uri=%2Fpath%2Fspam%2F&id=123').status_code, 404) self.assertEqual(self.get('/?uri=?uri=%foo%2F').status_code, 404) + def testGetLimited(self): + + for i in range(20): + self.post('/new?uri=test', data=json.dumps({'text': '...'})) + + r = self.get('/?uri=test&limit=10') + self.assertEqual(r.status_code, 200) + + rv = loads(r.data) + self.assertEqual(len(rv['replies']), 10) + + def testGetNested(self): + + self.post('/new?uri=test', data=json.dumps({'text': '...'})) + self.post('/new?uri=test', data=json.dumps({'text': '...', 'parent': 1})) + + r = self.get('/?uri=test&parent=1') + self.assertEqual(r.status_code, 200) + + rv = loads(r.data) + self.assertEqual(len(rv['replies']), 1) + + def testGetLimitedNested(self): + + self.post('/new?uri=test', data=json.dumps({'text': '...'})) + for i in range(20): + self.post('/new?uri=test', data=json.dumps({'text': '...', 'parent': 1})) + + r = self.get('/?uri=test&parent=1&limit=10') + self.assertEqual(r.status_code, 200) + + rv = loads(r.data) + self.assertEqual(len(rv['replies']), 10) + def testUpdate(self): self.post('/new?uri=%2Fpath%2F', data=json.dumps({'text': 'Lorem ipsum ...'})) From ab927e39d0484f505ab8866068bc81939f7f79d8 Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Sat, 3 May 2014 01:15:19 +0530 Subject: [PATCH 11/20] Add a reveal on click parameter --- isso/js/app/config.js | 1 + isso/js/app/isso.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/isso/js/app/config.js b/isso/js/app/config.js index d9fa133..ab700a5 100644 --- a/isso/js/app/config.js +++ b/isso/js/app/config.js @@ -7,6 +7,7 @@ define(function() { "reply-to-self": false, "max-comments-top": 20, "max-comments-nested": 5, + "reveal-on-click": "5", "avatar-bg": "#f0f0f0", "avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6", "#be5168", "#f19670", "#e4bf80", "#447c69"].join(" ") diff --git a/isso/js/app/isso.js b/isso/js/app/isso.js index 3cc780a..24e2779 100644 --- a/isso/js/app/isso.js +++ b/isso/js/app/isso.js @@ -100,9 +100,9 @@ define(["app/text/html", "app/dom", "app/utils", "app/config", "app/api", "app/m $("a.load_hidden", el).toggle("click", function() { el.remove(); - api.fetch($("#isso-thread").getAttribute("data-isso-id"), - limit = config["max-comments-top"], nested_limit=0, - parent=commentWrapper.id, + api.fetch($("#isso-thread").getAttribute("data-isso-id"), + limit = config["reveal-on-click"], nested_limit="0", + parent=commentWrapper.id, lastcreated=lastcreated).then( function(rv) { if (rv.total_replies == 0) { From baef73f1e8c30c912178d9cba337a791cee479e3 Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Sat, 3 May 2014 01:16:39 +0530 Subject: [PATCH 12/20] Change default values of config params --- isso/js/app/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/isso/js/app/config.js b/isso/js/app/config.js index ab700a5..bb79683 100644 --- a/isso/js/app/config.js +++ b/isso/js/app/config.js @@ -5,8 +5,8 @@ define(function() { "css": true, "lang": (navigator.language || navigator.userLanguage).split("-")[0], "reply-to-self": false, - "max-comments-top": 20, - "max-comments-nested": 5, + "max-comments-top": "10", + "max-comments-nested": "5", "reveal-on-click": "5", "avatar-bg": "#f0f0f0", "avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6", From 8879db59b8c0c691694c7872c806cda5334cc6d0 Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Sat, 3 May 2014 01:17:11 +0530 Subject: [PATCH 13/20] Show all comments if limit/nested_limit set as inf --- isso/js/app/api.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/isso/js/app/api.js b/isso/js/app/api.js index 2c5eba5..0bff7c0 100644 --- a/isso/js/app/api.js +++ b/isso/js/app/api.js @@ -129,12 +129,19 @@ define(["app/lib/promise", "app/globals"], function(Q, globals) { }; var fetch = function(tid, limit, nested_limit, parent, lastcreated) { - if(typeof(limit) == 'undefined') limit = 0; - if(typeof(nested_limit) == 'undefined') nested_limit = 0; + if(typeof(limit) == 'undefined') limit = "inf"; + if(typeof(nested_limit) == 'undefined') nested_limit = "inf"; if(typeof(parent) == 'undefined') parent = null; + var query_dict = {uri: tid || location, after: lastcreated, parent: parent}; + if(limit != "inf") { + query_dict['limit'] = limit; + } + if(nested_limit != "inf"){ + query_dict['nested_limit'] = nested_limit; + } var deferred = Q.defer(); curl("GET", endpoint + "/?" + - qs({uri: tid || location, limit: limit, nested_limit: nested_limit, after: lastcreated, parent: parent}), null, function(rv) { + qs(query_dict), null, function(rv) { if (rv.status === 200) { deferred.resolve(JSON.parse(rv.body)); } else if (rv.status === 404) { From 26d26ae71bc4958b6efe34873220ed86ebc43b96 Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Sat, 3 May 2014 01:37:28 +0530 Subject: [PATCH 14/20] Add i18n for "Hidden" --- isso/js/app/i18n/en.js | 1 + isso/js/app/text/comment-loader.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/isso/js/app/i18n/en.js b/isso/js/app/i18n/en.js index 40b5bc9..b23b3f5 100644 --- a/isso/js/app/i18n/en.js +++ b/isso/js/app/i18n/en.js @@ -17,6 +17,7 @@ define({ "comment-deleted": "Comment deleted.", "comment-queued": "Comment in queue for moderation.", "comment-anonymous": "Anonymous", + "comment-hidden": "Hidden", "date-now": "right now", "date-minute": "a minute ago\n{{ n }} minutes ago", diff --git a/isso/js/app/text/comment-loader.html b/isso/js/app/text/comment-loader.html index f6e7bad..ce507c6 100644 --- a/isso/js/app/text/comment-loader.html +++ b/isso/js/app/text/comment-loader.html @@ -1,3 +1,3 @@ \ No newline at end of file From 26ae30f76ce4fe46cca95c621684eb143670cdc3 Mon Sep 17 00:00:00 2001 From: Srijan Choudhary Date: Sat, 3 May 2014 01:52:32 +0530 Subject: [PATCH 15/20] Update docs --- docs/docs/configuration/client.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/docs/configuration/client.rst b/docs/docs/configuration/client.rst index 17f3e2a..819d2fe 100644 --- a/docs/docs/configuration/client.rst +++ b/docs/docs/configuration/client.rst @@ -10,6 +10,9 @@ preferably in the script tag which embeds the JS: data-isso-css="true" data-isso-lang="ru" data-isso-reply-to-self="false" + data-isso-max-comments-top="10" + data-isso-max-comments-nested="5" + data-isso-reveal-on-click="5" data-avatar-bg="#f0f0f0" data-avatar-fg="#9abf88 #5698c4 #e279a3 #9163b6 ..." src="/prefix/js/embed.js"> @@ -53,6 +56,19 @@ data-isso-reply-to-self Set to `true` when spam guard is configured with `reply-to-self = true`. +data-isso-max-comments-top and data-isso-max-comments-nested +------------------------------------------------------------ + +Number of top level (or nested) comments to show by default. If some +comments are not shown, an "X Hidden" link is shown. + +Set to `"inf"` to show all, or `"0"` to hide all. + +data-isso-reveal-on-click +------------------------- + +Number of comments to reveal on clicking the "X Hidden" link. + data-isso-avatar-bg ------------------- From 59bfde7c03506c962ece7d0726167f0fae6adb91 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Sat, 3 May 2014 10:47:48 +0200 Subject: [PATCH 16/20] idiomatic python * make "process_fetched_list" private * rename fetch_args to args * a few logic simplifications --- isso/db/comments.py | 4 +-- isso/views/comments.py | 81 +++++++++++++++++++----------------------- 2 files changed, 39 insertions(+), 46 deletions(-) diff --git a/isso/db/comments.py b/isso/db/comments.py index c88947a..350a3c9 100644 --- a/isso/db/comments.py +++ b/isso/db/comments.py @@ -108,7 +108,7 @@ class Comments: sql_args = [uri, mode, mode, after] if parent != 'any': - if parent is None or parent == 'NULL': + if parent is None: sql.append('AND comments.parent IS NULL') else: sql.append('AND comments.parent=?') @@ -117,7 +117,7 @@ class Comments: sql.append('ORDER BY ? ASC') sql_args.append(order_by) - if limit != None and limit != 0: + if limit: sql.append('LIMIT ?') sql_args.append(limit) diff --git a/isso/views/comments.py b/isso/views/comments.py index 94e4fa7..207c5c0 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -320,62 +320,54 @@ class API(object): @requires(str, 'uri') def fetch(self, environ, request, uri): - fetch_args={'uri': uri} - if request.args.get('after'): - fetch_args['after'] = request.args.get('after') - after = request.args.get('after') - else: - after = 0 - if request.args.get('limit'): - try: - fetch_args['limit'] = int(request.args.get('limit')) - except ValueError: - return BadRequest("limit should be integer") + args = { + 'uri': uri, + 'after': request.args.get('after', 0) + } - if request.args.get('parent'): - parent_arg = request.args.get('parent') - if parent_arg == 'NULL': - fetch_args['parent'] = parent_arg - root_id = None - else: - try: - fetch_args['parent'] = int(parent_arg) - root_id = int(parent_arg) - except ValueError: - return BadRequest("parent should be integer or NULL") + try: + args['limit'] = int(request.args.get('limit')) + except TypeError: + args['limit'] = None + except ValueError: + return BadRequest("limit should be integer") + + if request.args.get('parent') is not None: + try: + args['parent'] = int(request.args.get('parent')) + root_id = args['parent'] + except ValueError: + return BadRequest("parent should be integer") else: - fetch_args['parent'] = 'NULL' + args['parent'] = None root_id = None - if request.args.get('plain', '0') == '0': - plain = True - else: - plain = False + plain = request.args.get('plain', '0') == '0' - reply_counts = self.comments.reply_count(uri, after) + reply_counts = self.comments.reply_count(uri, args['after']) - if 'limit' in fetch_args and fetch_args['limit'] == 0: + if args['limit'] == 0: root_list = [] else: - root_list = list(self.comments.fetch(**fetch_args)) + root_list = list(self.comments.fetch(**args)) if not root_list: raise NotFound + if root_id not in reply_counts: reply_counts[root_id] = 0 - if request.args.get('nested_limit'): - try: - nested_limit = int(request.args.get('nested_limit')) - except ValueError: - return BadRequest("nested_limit should be integer") - else: + try: + nested_limit = int(request.args.get('nested_limit')) + except TypeError: nested_limit = None + except ValueError: + return BadRequest("nested_limit should be integer") rv = { 'id' : root_id, 'total_replies' : reply_counts[root_id], 'hidden_replies' : reply_counts[root_id] - len(root_list), - 'replies' : self.process_fetched_list(root_list, plain) + 'replies' : self._process_fetched_list(root_list, plain) } # We are only checking for one level deep comments if root_id is None: @@ -384,23 +376,24 @@ class API(object): comment['total_replies'] = reply_counts[comment['id']] if nested_limit is not None: if nested_limit > 0: - fetch_args['parent'] = comment['id'] - fetch_args['limit'] = nested_limit - replies = list(self.comments.fetch(**fetch_args)) + args['parent'] = comment['id'] + args['limit'] = nested_limit + replies = list(self.comments.fetch(**args)) else: replies = [] else: - fetch_args['parent'] = comment['id'] - replies = list(self.comments.fetch(**fetch_args)) + args['parent'] = comment['id'] + replies = list(self.comments.fetch(**args)) else: comment['total_replies'] = 0 replies = [] + comment['hidden_replies'] = comment['total_replies'] - len(replies) - comment['replies'] = self.process_fetched_list(replies, plain) + comment['replies'] = self._process_fetched_list(replies, plain) return JSON(rv, 200) - def process_fetched_list(self, fetched_list, plain=False): + def _process_fetched_list(self, fetched_list, plain=False): for item in fetched_list: key = item['email'] or item['remote_addr'] From f3a7f65687f9509f243675c243440d3179451303 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Sat, 3 May 2014 10:48:57 +0200 Subject: [PATCH 17/20] remove keyworded function arguments and fix JS hints --- isso/js/app/api.js | 16 ++++++++++------ isso/js/app/isso.js | 10 +++++----- isso/js/embed.js | 7 +++---- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/isso/js/app/api.js b/isso/js/app/api.js index 0bff7c0..1108c0a 100644 --- a/isso/js/app/api.js +++ b/isso/js/app/api.js @@ -78,7 +78,8 @@ define(["app/lib/promise", "app/globals"], function(Q, globals) { var qs = function(params) { var rv = ""; for (var key in params) { - if (params.hasOwnProperty(key) && params[key]) { + if (params.hasOwnProperty(key) && + params[key] !== null && typeof(params[key]) !== "undefined") { rv += key + "=" + encodeURIComponent(params[key]) + "&"; } } @@ -129,16 +130,19 @@ define(["app/lib/promise", "app/globals"], function(Q, globals) { }; var fetch = function(tid, limit, nested_limit, parent, lastcreated) { - if(typeof(limit) == 'undefined') limit = "inf"; - if(typeof(nested_limit) == 'undefined') nested_limit = "inf"; - if(typeof(parent) == 'undefined') parent = null; + if (typeof(limit) === 'undefined') { limit = "inf"; } + if (typeof(nested_limit) === 'undefined') { nested_limit = "inf"; } + if (typeof(parent) === 'undefined') { parent = null; } + var query_dict = {uri: tid || location, after: lastcreated, parent: parent}; - if(limit != "inf") { + + if(limit !== "inf") { query_dict['limit'] = limit; } - if(nested_limit != "inf"){ + if(nested_limit !== "inf"){ query_dict['nested_limit'] = nested_limit; } + var deferred = Q.defer(); curl("GET", endpoint + "/?" + qs(query_dict), null, function(rv) { diff --git a/isso/js/app/isso.js b/isso/js/app/isso.js index 24e2779..a7971d8 100644 --- a/isso/js/app/isso.js +++ b/isso/js/app/isso.js @@ -101,11 +101,11 @@ define(["app/text/html", "app/dom", "app/utils", "app/config", "app/api", "app/m function() { el.remove(); api.fetch($("#isso-thread").getAttribute("data-isso-id"), - limit = config["reveal-on-click"], nested_limit="0", - parent=commentWrapper.id, - lastcreated=lastcreated).then( + config["reveal-on-click"], "0", + commentWrapper.id, + lastcreated).then( function(rv) { - if (rv.total_replies == 0) { + if (rv.total_replies === 0) { return; } @@ -172,7 +172,7 @@ define(["app/text/html", "app/dom", "app/utils", "app/config", "app/api", "app/m $("a.reply", footer).textContent = msgs["comment-close"]; }, function() { - form.remove() + form.remove(); $("a.reply", footer).textContent = msgs["comment-reply"]; } ); diff --git a/isso/js/embed.js b/isso/js/embed.js index 4bdd98a..29d64ad 100644 --- a/isso/js/embed.js +++ b/isso/js/embed.js @@ -26,10 +26,9 @@ require(["app/lib/ready", "app/config", "app/api", "app/isso", "app/count", "app $("#isso-thread").append(new isso.Postbox(null)); $("#isso-thread").append('
'); - api.fetch($("#isso-thread").getAttribute("data-isso-id"), - limit = config["max-comments-top"], - nested_limit = config["max-comments-nested"], - parent='NULL').then( + api.fetch($("#isso-thread").getAttribute("data-isso-id"), + config["max-comments-top"], + config["max-comments-nested"]).then( function(rv) { if (rv.total_replies == 0) { $("#isso-thread > h4").textContent = Mark.up("{{ i18n-no-comments }}"); From 324326c2ba231b93fcf9d6682edbb43e2e835c75 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Sat, 3 May 2014 11:58:09 +0200 Subject: [PATCH 18/20] translate Hidden to german and french --- isso/js/app/i18n/de.js | 1 + isso/js/app/i18n/en.js | 2 +- isso/js/app/i18n/fr.js | 1 + isso/js/app/text/comment-loader.html | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/isso/js/app/i18n/de.js b/isso/js/app/i18n/de.js index dcdbac3..98c4d61 100644 --- a/isso/js/app/i18n/de.js +++ b/isso/js/app/i18n/de.js @@ -15,6 +15,7 @@ define({ "comment-deleted": "Kommentar gelöscht.", "comment-queued": "Kommentar muss noch freigeschaltet werden.", "comment-anonymous": "Anonym", + "comment-hidden": "{{ hidden_replies }} versteckt", "date-now": "eben jetzt", "date-minute": "vor einer Minute\nvor {{ n }} Minuten", "date-hour": "vor einer Stunde\nvor {{ n }} Stunden", diff --git a/isso/js/app/i18n/en.js b/isso/js/app/i18n/en.js index b23b3f5..6cc1d45 100644 --- a/isso/js/app/i18n/en.js +++ b/isso/js/app/i18n/en.js @@ -17,7 +17,7 @@ define({ "comment-deleted": "Comment deleted.", "comment-queued": "Comment in queue for moderation.", "comment-anonymous": "Anonymous", - "comment-hidden": "Hidden", + "comment-hidden": "{{ hidden_replies }} Hidden", "date-now": "right now", "date-minute": "a minute ago\n{{ n }} minutes ago", diff --git a/isso/js/app/i18n/fr.js b/isso/js/app/i18n/fr.js index db72936..19d71a6 100644 --- a/isso/js/app/i18n/fr.js +++ b/isso/js/app/i18n/fr.js @@ -15,6 +15,7 @@ define({ "comment-deleted": "Commentaire supprimé.", "comment-queued": "Commentaire en attente de modération.", "comment-anonymous": "Anonyme", + "comment-hidden": "1 caché\n{{ hidden_replies }} cachés", "date-now": "À l'instant'", "date-minute": "Il y a une minute \n{{ n }} minutes", "date-hour": "Il y a une heure\n{{ n }} heures ", diff --git a/isso/js/app/text/comment-loader.html b/isso/js/app/text/comment-loader.html index ce507c6..2e37e4b 100644 --- a/isso/js/app/text/comment-loader.html +++ b/isso/js/app/text/comment-loader.html @@ -1,3 +1,3 @@ \ No newline at end of file From ed810cdf398913d99be8e2b3d261919688200020 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Sat, 3 May 2014 12:00:17 +0200 Subject: [PATCH 19/20] fetch all nested comments when set to 'inf' --- isso/js/app/isso.js | 2 +- isso/js/embed.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/isso/js/app/isso.js b/isso/js/app/isso.js index a7971d8..da78ea0 100644 --- a/isso/js/app/isso.js +++ b/isso/js/app/isso.js @@ -101,7 +101,7 @@ define(["app/text/html", "app/dom", "app/utils", "app/config", "app/api", "app/m function() { el.remove(); api.fetch($("#isso-thread").getAttribute("data-isso-id"), - config["reveal-on-click"], "0", + config["reveal-on-click"], config["max-comments-nested"], commentWrapper.id, lastcreated).then( function(rv) { diff --git a/isso/js/embed.js b/isso/js/embed.js index 29d64ad..6e6d8de 100644 --- a/isso/js/embed.js +++ b/isso/js/embed.js @@ -30,7 +30,7 @@ require(["app/lib/ready", "app/config", "app/api", "app/isso", "app/count", "app config["max-comments-top"], config["max-comments-nested"]).then( function(rv) { - if (rv.total_replies == 0) { + if (rv.total_replies === 0) { $("#isso-thread > h4").textContent = Mark.up("{{ i18n-no-comments }}"); return; } From d5e5e9c7e20e8ba898d17c57b49f1f9816f5c2e1 Mon Sep 17 00:00:00 2001 From: Martin Zimmermann Date: Sat, 3 May 2014 12:00:46 +0200 Subject: [PATCH 20/20] use numerical values in default configuration to match user-provided values --- isso/js/app/config.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/isso/js/app/config.js b/isso/js/app/config.js index bb79683..aa092ed 100644 --- a/isso/js/app/config.js +++ b/isso/js/app/config.js @@ -5,9 +5,9 @@ define(function() { "css": true, "lang": (navigator.language || navigator.userLanguage).split("-")[0], "reply-to-self": false, - "max-comments-top": "10", - "max-comments-nested": "5", - "reveal-on-click": "5", + "max-comments-top": 10, + "max-comments-nested": 5, + "reveal-on-click": 5, "avatar-bg": "#f0f0f0", "avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6", "#be5168", "#f19670", "#e4bf80", "#447c69"].join(" ")