Skip to content
Snippets Groups Projects
Commit ff4f0cd2 authored by echicken's avatar echicken :chicken:
Browse files

Added get-thread call, support for generatorish reply value. list-threads...

Added get-thread call, support for generatorish reply value. list-threads doesn't need offset, instead will begin at the message after 'after' if given.
parent c7169a53
Branches
Tags
No related merge requests found
......@@ -160,6 +160,13 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
}
break;
case 'get-thread':
if (Request.has_params(['sub', 'thread'])) {
if (Request.has_param('count')) var count = Request.get_param('count');
reply = getMessageThread(Request.get_param('sub'), Request.get_param('thread'), count || settings.page_size, Request.get_param('after'));
}
break;
case 'list-groups':
reply = listGroups();
break;
......@@ -169,9 +176,9 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
break;
case 'list-threads':
if (Request.has_params(['sub', 'offset'])) {
if (Request.has_param('count')) var count = http_request.query.count[0];
reply = listThreads(http_request.query.sub[0], http_request.query.offset[0], count || settings.page_size).threads;
if (Request.has_param('sub')) {
if (Request.has_param('count')) var count = Request.get_param(count);
reply = listThreads(Request.get_param('sub'), count || settings.page_size, Request.get_param('after'));
}
break;
......@@ -188,7 +195,15 @@ if (Request.has_param('call') && (http_request.method === 'GET' || http_request.
}
reply = JSON.stringify(reply);
http_reply.header['Content-Type'] = 'application/json';
http_reply.header['Content-Length'] = reply.length;
write(reply);
if (typeof reply === 'function') { // generator
var r;
http_reply.header['Content-Type'] = 'application/json';
while ((r = reply()) !== null) {
writeln(JSON.stringify(r));
}
} else { // Normal reply
reply = JSON.stringify(reply);
http_reply.header['Content-Type'] = 'application/json';
http_reply.header['Content-Length'] = reply.length;
write(reply);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment