Add max-comments limit for nested replies
This commit is contained in:
parent
f5da45e525
commit
54b156844b
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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(" ")
|
||||
|
@ -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;
|
||||
|
@ -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('<div id="isso-root"></div>');
|
||||
|
||||
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 }}");
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user