message_fetch: Deduplicate logic for finish_older_batch.

Previously, each individual caller of load_messages that passed
num_before > 0 would do its own manual management of fetch_status;
now, we just do it inside load_messages.
This commit is contained in:
Tim Abbott
2018-12-12 15:57:40 -08:00
parent cd118bbc7e
commit 9ccb3a2ad1
3 changed files with 24 additions and 33 deletions

View File

@@ -48,11 +48,13 @@ run_test('basics', () => {
can_load_history();
has_not_found_newest();
fetch_status.finish_initial_narrow({
var data = {
found_oldest: true,
found_newest: true,
history_limited: true,
});
};
fetch_status.finish_initial_narrow(data);
fetch_status.finish_older_batch(data);
has_found_newest();
blocked_newer();
@@ -67,11 +69,13 @@ run_test('basics', () => {
blocked_older();
can_load_history();
fetch_status.finish_initial_narrow({
data = {
found_oldest: false,
found_newest: false,
history_limited: false,
});
};
fetch_status.finish_initial_narrow(data);
fetch_status.finish_older_batch(data);
can_load_older();
can_load_newer();

View File

@@ -15,10 +15,7 @@ var FetchStatus = function () {
self.finish_initial_narrow = function (opts) {
loading_newer = false;
loading_older = false;
found_oldest = opts.found_oldest;
found_newest = opts.found_newest;
history_limited = opts.history_limited;
};
self.start_older_batch = function () {

View File

@@ -56,11 +56,24 @@ function process_result(data, opts) {
stream_list.maybe_scroll_narrow_into_view();
if (opts.cont !== undefined) {
opts.cont(data, opts);
opts.cont(data);
}
}
function get_messages_success(data, opts) {
if (opts.num_before > 0) {
opts.msg_list.fetch_status.finish_older_batch({
found_oldest: data.found_oldest,
history_limited: data.history_limited,
});
if (opts.msg_list === home_msg_list) {
message_list.all.fetch_status.finish_older_batch({
found_oldest: data.found_oldest,
history_limited: data.history_limited,
});
}
}
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.
@@ -223,17 +236,7 @@ exports.do_backfill = function (opts) {
num_before: opts.num_before,
num_after: 0,
msg_list: msg_list,
cont: function (data) {
msg_list.fetch_status.finish_older_batch({
found_oldest: data.found_oldest,
history_limited: data.history_limited,
});
if (msg_list === home_msg_list) {
message_list.all.fetch_status.finish_older_batch({
found_oldest: data.found_oldest,
history_limited: data.history_limited,
});
}
cont: function () {
if (opts.cont) {
opts.cont();
}
@@ -291,7 +294,7 @@ exports.start_backfilling_messages = function () {
exports.initialize = function () {
// get the initial message list
function load_more(data, opts) {
function load_more(data) {
// 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.
//
@@ -303,19 +306,6 @@ exports.initialize = function () {
target_scroll_offset: page_params.initial_offset});
}
if (opts.num_before > 0) {
// Only the initial call with num_before=consts.num_before_pointer
// has an older batch to finish.
home_msg_list.fetch_status.finish_older_batch({
found_oldest: data.found_oldest,
history_limited: data.history_limited,
});
message_list.all.fetch_status.finish_older_batch({
found_oldest: data.found_oldest,
history_limited: data.history_limited,
});
}
home_msg_list.fetch_status.finish_newer_batch({
found_newest: data.found_newest,
});