mirror of https://github.com/zulip/zulip.git
API: Add support for nonblocking get_updates requests.
(imported from commit bf2ab19a83765c177fbb93abc1a61dccf5b4b2b7)
This commit is contained in:
parent
be27ec1ad4
commit
eefa5b2d7b
|
@ -177,7 +177,7 @@ var people_list = [
|
|||
|
||||
<div class="alert alert_sidebar alert-error home-error-bar" id="connection-error">
|
||||
<strong>Can't receive messages</strong>
|
||||
— retrying soon. <a class="cursor_pointer" onclick="restart_get_updates()">Try now</a>.
|
||||
— retrying soon. <a class="cursor_pointer" onclick="restart_get_updates({dont_block: true});">Try now</a>.
|
||||
</div>
|
||||
<div class="alert alert_sidebar alert-error home-error-bar" id="reloading-application">
|
||||
</div>
|
||||
|
|
|
@ -558,9 +558,13 @@ function add_messages(messages, add_to_home) {
|
|||
|
||||
var get_updates_xhr;
|
||||
var get_updates_timeout;
|
||||
function get_updates() {
|
||||
function get_updates(options) {
|
||||
var defaults = {dont_block: false};
|
||||
options = $.extend({}, defaults, options);
|
||||
|
||||
get_updates_params.pointer = selected_message_id;
|
||||
get_updates_params.reload_pending = Number(reload.is_pending());
|
||||
get_updates_params.dont_block = options.dont_block;
|
||||
|
||||
get_updates_xhr = $.ajax({
|
||||
type: 'POST',
|
||||
|
@ -708,14 +712,14 @@ $(function () {
|
|||
}
|
||||
});
|
||||
|
||||
function restart_get_updates() {
|
||||
function restart_get_updates(options) {
|
||||
if (get_updates_xhr !== undefined)
|
||||
get_updates_xhr.abort();
|
||||
|
||||
if (get_updates_timeout !== undefined)
|
||||
clearTimeout(get_updates_timeout);
|
||||
|
||||
get_updates();
|
||||
get_updates(options);
|
||||
}
|
||||
|
||||
function load_more_messages() {
|
||||
|
|
|
@ -335,7 +335,7 @@ def format_delayed_updates_response(request=None, user_profile=None,
|
|||
|
||||
def return_messages_immediately(user_profile, client_id, last,
|
||||
failures, client_server_generation,
|
||||
client_reload_pending, **kwargs):
|
||||
client_reload_pending, dont_block, **kwargs):
|
||||
if last is None:
|
||||
# When an API user is first querying the server to subscribe,
|
||||
# there's no reason to reply immediately.
|
||||
|
@ -378,6 +378,9 @@ def return_messages_immediately(user_profile, client_id, last,
|
|||
if messages:
|
||||
update_types.append("new_messages")
|
||||
|
||||
if dont_block:
|
||||
update_types.append("nonblocking_request")
|
||||
|
||||
if (client_server_generation is not None
|
||||
and int(client_server_generation) != SERVER_GENERATION
|
||||
and not client_reload_pending):
|
||||
|
@ -424,10 +427,12 @@ def get_updates_backend(request, user_profile, handler, client_id,
|
|||
failures = POST(converter=int, default=None),
|
||||
client_server_generation = POST(whence='server_generation', default=None),
|
||||
client_reload_pending = POST(whence='server_generation', default=None),
|
||||
dont_block = POST(converter=simplejson.loads, default=False),
|
||||
**kwargs):
|
||||
resp = return_messages_immediately(user_profile, client_id, last, failures,
|
||||
client_server_generation,
|
||||
client_reload_pending, **kwargs)
|
||||
client_reload_pending,
|
||||
dont_block, **kwargs)
|
||||
if resp is not None:
|
||||
send_with_safety_check(resp, handler, **kwargs)
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue