message_fetch: Deduplicate logic for finish_newer_batch.

Like the other similar commits, we were doing the same work in all
code paths, just with a much more error-prone approach.

We can also now remove the now-unused finish_initial_narrow function.
This commit is contained in:
Tim Abbott 2018-12-12 16:13:29 -08:00
parent ce187b0899
commit 1054d63820
3 changed files with 14 additions and 30 deletions

View File

@ -54,7 +54,7 @@ run_test('basics', () => {
found_newest: true,
history_limited: true,
};
fetch_status.finish_initial_narrow(data);
fetch_status.finish_newer_batch(data);
fetch_status.finish_older_batch(data);
has_found_newest();
@ -76,7 +76,7 @@ run_test('basics', () => {
found_newest: false,
history_limited: false,
};
fetch_status.finish_initial_narrow(data);
fetch_status.finish_newer_batch(data);
fetch_status.finish_older_batch(data);
can_load_older();

View File

@ -8,11 +8,6 @@ var FetchStatus = function () {
var found_newest = false;
var history_limited = false;
self.finish_initial_narrow = function (opts) {
loading_newer = false;
found_newest = opts.found_newest;
};
self.start_older_batch = function () {
loading_older = true;
};

View File

@ -74,6 +74,17 @@ function get_messages_success(data, opts) {
}
}
if (opts.num_after > 0) {
opts.msg_list.fetch_status.finish_newer_batch({
found_newest: data.found_newest,
});
if (opts.msg_list === home_msg_list) {
message_list.all.fetch_status.finish_newer_batch({
found_newest: data.found_newest,
});
}
}
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.
@ -172,11 +183,7 @@ exports.load_messages_for_narrow = function (opts) {
num_after: consts.narrow_after,
msg_list: msg_list,
use_first_unread_anchor: opts.use_first_unread_anchor,
cont: function (data) {
msg_list.fetch_status.finish_initial_narrow({
found_oldest: data.found_oldest,
found_newest: data.found_newest,
});
cont: function () {
message_scroll.hide_indicators();
opts.cont();
},
@ -269,16 +276,6 @@ exports.maybe_load_newer_messages = function (opts) {
num_before: 0,
num_after: consts.forward_batch_size,
msg_list: msg_list,
cont: function (data) {
msg_list.fetch_status.finish_newer_batch({
found_newest: data.found_newest,
});
if (msg_list === home_msg_list) {
message_list.all.fetch_status.finish_newer_batch({
found_newest: data.found_newest,
});
}
},
});
};
@ -307,14 +304,6 @@ exports.initialize = function () {
target_scroll_offset: page_params.initial_offset});
}
home_msg_list.fetch_status.finish_newer_batch({
found_newest: data.found_newest,
});
message_list.all.fetch_status.finish_newer_batch({
found_newest: data.found_newest,
});
if (data.found_newest) {
server_events.home_view_loaded();
exports.start_backfilling_messages();