mirror of https://github.com/zulip/zulip.git
Move the get_old_messages success work into its own function.
We'll need to set timeouts on calling this function. (imported from commit 02b8322ae3cd68d714c2ccf4b5bece075cc8d27f)
This commit is contained in:
parent
a1f760dedb
commit
5b38b763d9
|
@ -1019,18 +1019,7 @@ function force_get_updates() {
|
|||
get_updates_timeout = setTimeout(get_updates, 0);
|
||||
}
|
||||
|
||||
function load_old_messages(opts) {
|
||||
opts = _.extend({cont_will_add_messages: false}, opts);
|
||||
|
||||
var data = {anchor: opts.anchor,
|
||||
num_before: opts.num_before,
|
||||
num_after: opts.num_after};
|
||||
|
||||
if (opts.msg_list.narrowed && narrow.active()) {
|
||||
data.narrow = JSON.stringify(narrow.public_operators());
|
||||
}
|
||||
|
||||
function process_result(messages) {
|
||||
function process_result(messages, opts) {
|
||||
$('#get_old_messages_error').hide();
|
||||
|
||||
if ((messages.length === 0) && (current_msg_list === narrowed_msg_list) &&
|
||||
|
@ -1059,14 +1048,9 @@ function load_old_messages(opts) {
|
|||
if (opts.cont !== undefined) {
|
||||
opts.cont(messages);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/json/get_old_messages',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
function get_old_messages_success(data, opts) {
|
||||
if (opts.msg_list.narrowed && opts.msg_list !== current_msg_list) {
|
||||
// We unnarrowed before receiving new messages so
|
||||
// don't bother processing the newly arrived messages.
|
||||
|
@ -1081,7 +1065,27 @@ function load_old_messages(opts) {
|
|||
return;
|
||||
}
|
||||
|
||||
process_result(data.messages);
|
||||
process_result(data.messages, opts);
|
||||
}
|
||||
|
||||
function load_old_messages(opts) {
|
||||
opts = _.extend({cont_will_add_messages: false}, opts);
|
||||
|
||||
var data = {anchor: opts.anchor,
|
||||
num_before: opts.num_before,
|
||||
num_after: opts.num_after};
|
||||
|
||||
if (opts.msg_list.narrowed && narrow.active()) {
|
||||
data.narrow = JSON.stringify(narrow.public_operators());
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/json/get_old_messages',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
success: function (data) {
|
||||
get_old_messages_success(data, opts);
|
||||
},
|
||||
error: function (xhr, error_type, exn) {
|
||||
if (opts.msg_list.narrowed && opts.msg_list !== current_msg_list) {
|
||||
|
@ -1095,7 +1099,7 @@ function load_old_messages(opts) {
|
|||
// retry or display a connection error.
|
||||
//
|
||||
// FIXME: Warn the user when this has happened?
|
||||
process_result([]);
|
||||
process_result([], opts);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue