message_fetch: Use found_oldest flag from server.

We now use the found_oldest flag from the server to determine
whether we should load older messages.

This requires us to change a few places in the code where we
pass the whole payload around now instead of just the messages.

Actually, many of the "cont" callbacks don't even look at the
data, so this change wasn't as invasive as I might have
predicted.
This commit is contained in:
Steve Howell
2018-03-16 08:05:54 -04:00
committed by Tim Abbott
parent 93678e89cd
commit 58c1427859

View File

@@ -14,7 +14,9 @@ var consts = {
catch_up_batch_size: 1000, catch_up_batch_size: 1000,
}; };
function process_result(messages, opts) { function process_result(data, opts) {
var messages = data.messages;
$('#connection-error').removeClass("show"); $('#connection-error').removeClass("show");
if ((messages.length === 0) && (current_msg_list === message_list.narrowed) && if ((messages.length === 0) && (current_msg_list === message_list.narrowed) &&
@@ -44,7 +46,7 @@ function process_result(messages, opts) {
pm_list.update_private_messages(); pm_list.update_private_messages();
if (opts.cont !== undefined) { if (opts.cont !== undefined) {
opts.cont(messages); opts.cont(data);
} }
} }
@@ -63,7 +65,7 @@ function get_messages_success(data, opts) {
return; return;
} }
process_result(data.messages, opts); process_result(data, opts);
resize.resize_bottom_whitespace(); resize.resize_bottom_whitespace();
} }
@@ -108,7 +110,10 @@ exports.load_messages = function (opts) {
// retry or display a connection error. // retry or display a connection error.
// //
// FIXME: Warn the user when this has happened? // FIXME: Warn the user when this has happened?
process_result([], opts); var data = {
messages: [],
};
process_result(data, opts);
return; return;
} }
@@ -164,11 +169,10 @@ exports.maybe_load_older_messages = function (opts) {
num_before: batch_size, num_before: batch_size,
num_after: 0, num_after: 0,
msg_list: msg_list, msg_list: msg_list,
cont: function (messages) { cont: function (data) {
opts.hide_loading(); opts.hide_loading();
var found_oldest = messages.length < batch_size;
msg_list.fetch_status.finish_older_batch({ msg_list.fetch_status.finish_older_batch({
found_oldest: found_oldest, found_oldest: data.found_oldest,
}); });
}, },
}); });
@@ -176,7 +180,8 @@ exports.maybe_load_older_messages = function (opts) {
exports.initialize = function () { exports.initialize = function () {
// get the initial message list // get the initial message list
function load_more(messages) { function load_more(data) {
var messages = data.messages;
// If we received the initially selected message, select it on the client side, // If we received the initially selected message, select it on the client side,
// but not if the user has already selected another one during load. // but not if the user has already selected another one during load.