message view: Refactor top loading indicators.

This commit makes the `loading_older_messages_indicator` similar
to the `loading_newer_messages_indicator`.
Now all the decisions about whether to show a loading indicator
will be made from the `fetch_status` API. We still hide the
indicators everytime the view is changed, as explained in the
previous commit.
This commit is contained in:
Ryan Rehman
2020-06-15 16:17:11 +05:30
committed by Tim Abbott
parent e0b1fdb81c
commit a630f291b9
6 changed files with 25 additions and 15 deletions

View File

@@ -1,5 +1,7 @@
const FetchStatus = zrequire('fetch_status'); const FetchStatus = zrequire('fetch_status');
set_global('message_scroll', { set_global('message_scroll', {
hide_loading_older: () => {},
show_loading_older: () => {},
hide_loading_newer: () => {}, hide_loading_newer: () => {},
show_loading_newer: () => {}, show_loading_newer: () => {},
}); });
@@ -54,7 +56,7 @@ run_test('basics', () => {
reset(); reset();
fetch_status.start_newer_batch({ update_loading_indicator: false }); fetch_status.start_newer_batch({ update_loading_indicator: false });
fetch_status.start_older_batch(); fetch_status.start_older_batch({ update_loading_indicator: false });
blocked_newer(); blocked_newer();
blocked_older(); blocked_older();
@@ -80,7 +82,7 @@ run_test('basics', () => {
reset(); reset();
fetch_status.start_newer_batch({ update_loading_indicator: true }); fetch_status.start_newer_batch({ update_loading_indicator: true });
fetch_status.start_older_batch(); fetch_status.start_older_batch({ update_loading_indicator: true });
blocked_newer(); blocked_newer();
blocked_older(); blocked_older();
@@ -103,13 +105,14 @@ run_test('basics', () => {
can_load_older(); can_load_older();
fetch_status.start_older_batch(); fetch_status.start_older_batch({ update_loading_indicator: false });
blocked_older(); blocked_older();
can_load_newer(); can_load_newer();
can_load_history(); can_load_history();
fetch_status.finish_older_batch({ fetch_status.finish_older_batch({
update_loading_indicator: true,
found_oldest: false, found_oldest: false,
history_limited: false, history_limited: false,
}); });
@@ -118,13 +121,14 @@ run_test('basics', () => {
can_load_newer(); can_load_newer();
can_load_history(); can_load_history();
fetch_status.start_older_batch(); fetch_status.start_older_batch({ update_loading_indicator: true });
blocked_older(); blocked_older();
can_load_newer(); can_load_newer();
can_load_history(); can_load_history();
fetch_status.finish_older_batch({ fetch_status.finish_older_batch({
update_loading_indicator: true,
found_oldest: true, found_oldest: true,
history_limited: true, history_limited: true,
}); });

View File

@@ -26,6 +26,8 @@ set_global('ui_report', {
set_global('channel', {}); set_global('channel', {});
set_global('document', 'document-stub'); set_global('document', 'document-stub');
set_global('message_scroll', { set_global('message_scroll', {
show_loading_older: noop,
hide_loading_older: noop,
show_loading_newer: noop, show_loading_newer: noop,
hide_loading_newer: noop, hide_loading_newer: noop,
}); });

View File

@@ -8,14 +8,20 @@ const FetchStatus = function () {
let found_newest = false; let found_newest = false;
let history_limited = false; let history_limited = false;
self.start_older_batch = function () { self.start_older_batch = function (opts) {
loading_older = true; loading_older = true;
if (opts.update_loading_indicator) {
message_scroll.show_loading_older();
}
}; };
self.finish_older_batch = function (opts) { self.finish_older_batch = function (opts) {
loading_older = false; loading_older = false;
found_oldest = opts.found_oldest; found_oldest = opts.found_oldest;
history_limited = opts.history_limited; history_limited = opts.history_limited;
if (opts.update_loading_indicator) {
message_scroll.hide_loading_older();
}
}; };
self.can_load_older_messages = function () { self.can_load_older_messages = function () {

View File

@@ -64,6 +64,7 @@ function get_messages_success(data, opts) {
const update_loading_indicator = opts.msg_list === current_msg_list; const update_loading_indicator = opts.msg_list === current_msg_list;
if (opts.num_before > 0) { if (opts.num_before > 0) {
opts.msg_list.data.fetch_status.finish_older_batch({ opts.msg_list.data.fetch_status.finish_older_batch({
update_loading_indicator: update_loading_indicator,
found_oldest: data.found_oldest, found_oldest: data.found_oldest,
history_limited: data.history_limited, history_limited: data.history_limited,
}); });
@@ -73,6 +74,7 @@ function get_messages_success(data, opts) {
// which is never rendered (and just used for // which is never rendered (and just used for
// prepopulating narrowed views). // prepopulating narrowed views).
message_list.all.data.fetch_status.finish_older_batch({ message_list.all.data.fetch_status.finish_older_batch({
update_loading_indicator: false,
found_oldest: data.found_oldest, found_oldest: data.found_oldest,
history_limited: data.history_limited, history_limited: data.history_limited,
}); });
@@ -174,9 +176,13 @@ exports.load_messages = function (opts) {
const update_loading_indicator = opts.msg_list === current_msg_list; const update_loading_indicator = opts.msg_list === current_msg_list;
if (opts.num_before > 0) { if (opts.num_before > 0) {
opts.msg_list.data.fetch_status.start_older_batch(); opts.msg_list.data.fetch_status.start_older_batch({
update_loading_indicator: update_loading_indicator,
});
if (opts.msg_list === home_msg_list) { if (opts.msg_list === home_msg_list) {
message_list.all.data.fetch_status.start_older_batch(); message_list.all.data.fetch_status.start_older_batch({
update_loading_indicator: update_loading_indicator,
});
} }
} }
@@ -284,13 +290,9 @@ exports.maybe_load_older_messages = function (opts) {
return; return;
} }
opts.show_loading();
exports.do_backfill({ exports.do_backfill({
msg_list: msg_list, msg_list: msg_list,
num_before: consts.backward_batch_size, num_before: consts.backward_batch_size,
cont: function () {
opts.hide_loading();
},
}); });
}; };

View File

@@ -63,8 +63,6 @@ exports.scroll_finished = function () {
if (message_viewport.at_top()) { if (message_viewport.at_top()) {
message_fetch.maybe_load_older_messages({ message_fetch.maybe_load_older_messages({
msg_list: current_msg_list, msg_list: current_msg_list,
show_loading: exports.show_loading_older,
hide_loading: exports.hide_loading_older,
}); });
} }

View File

@@ -299,8 +299,6 @@ exports.activate = function (raw_operators, opts) {
id_info: id_info, id_info: id_info,
select_offset: then_select_offset, select_offset: then_select_offset,
}); });
} else {
message_scroll.show_loading_older();
} }
// Put the narrow operators in the URL fragment. // Put the narrow operators in the URL fragment.