Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message view: Refactor top loading indicators.
Ryan Rehmana630f291b985
diff --git a/frontend_tests/node_tests/fetch_status.js b/frontend_tests/node_tests/fetch_status.jsindex 2a98600e596..b2cece363a4 100644--- a/frontend_tests/node_tests/fetch_status.js+++ b/frontend_tests/node_tests/fetch_status.js@@ -1,5 +1,7 @@const FetchStatus = zrequire('fetch_status');set_global('message_scroll', {+ hide_loading_older: () => {},+ show_loading_older: () => {},hide_loading_newer: () => {},show_loading_newer: () => {},});@@ -54,7 +56,7 @@ run_test('basics', () => {reset();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_older();@@ -80,7 +82,7 @@ run_test('basics', () => {reset();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_older();@@ -103,13 +105,14 @@ run_test('basics', () => {can_load_older();- fetch_status.start_older_batch();+ fetch_status.start_older_batch({ update_loading_indicator: false });blocked_older();can_load_newer();can_load_history();fetch_status.finish_older_batch({+ update_loading_indicator: true,found_oldest: false,history_limited: false,});@@ -118,13 +121,14 @@ run_test('basics', () => {can_load_newer();can_load_history();- fetch_status.start_older_batch();+ fetch_status.start_older_batch({ update_loading_indicator: true });blocked_older();can_load_newer();can_load_history();fetch_status.finish_older_batch({+ update_loading_indicator: true,found_oldest: true,history_limited: true,});diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.jsindex a86807406c5..8b499c026fb 100644--- a/frontend_tests/node_tests/message_fetch.js+++ b/frontend_tests/node_tests/message_fetch.js@@ -26,6 +26,8 @@ set_global('ui_report', {set_global('channel', {});set_global('document', 'document-stub');set_global('message_scroll', {+ show_loading_older: noop,+ hide_loading_older: noop,show_loading_newer: noop,hide_loading_newer: noop,});diff --git a/static/js/fetch_status.js b/static/js/fetch_status.jsindex 34b2e2763cf..fd09bd45027 100644--- a/static/js/fetch_status.js+++ b/static/js/fetch_status.js@@ -8,14 +8,20 @@ const FetchStatus = function () {let found_newest = false;let history_limited = false;- self.start_older_batch = function () {+ self.start_older_batch = function (opts) {loading_older = true;+ if (opts.update_loading_indicator) {+ message_scroll.show_loading_older();+ }};self.finish_older_batch = function (opts) {loading_older = false;found_oldest = opts.found_oldest;history_limited = opts.history_limited;+ if (opts.update_loading_indicator) {+ message_scroll.hide_loading_older();+ }};self.can_load_older_messages = function () {diff --git a/static/js/message_fetch.js b/static/js/message_fetch.jsindex 2355e6e995d..dc88fcd8a46 100644--- a/static/js/message_fetch.js+++ b/static/js/message_fetch.js@@ -64,6 +64,7 @@ function get_messages_success(data, opts) {const update_loading_indicator = opts.msg_list === current_msg_list;if (opts.num_before > 0) {opts.msg_list.data.fetch_status.finish_older_batch({+ update_loading_indicator: update_loading_indicator,found_oldest: data.found_oldest,history_limited: data.history_limited,});@@ -73,6 +74,7 @@ function get_messages_success(data, opts) {// which is never rendered (and just used for// prepopulating narrowed views).message_list.all.data.fetch_status.finish_older_batch({+ update_loading_indicator: false,found_oldest: data.found_oldest,history_limited: data.history_limited,});@@ -174,9 +176,13 @@ exports.load_messages = function (opts) {const update_loading_indicator = opts.msg_list === current_msg_list;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) {- 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;}- opts.show_loading();exports.do_backfill({msg_list: msg_list,num_before: consts.backward_batch_size,- cont: function () {- opts.hide_loading();- },});};diff --git a/static/js/message_scroll.js b/static/js/message_scroll.jsindex 50f83156d3e..c386019ad5e 100644--- a/static/js/message_scroll.js+++ b/static/js/message_scroll.js@@ -63,8 +63,6 @@ exports.scroll_finished = function () {if (message_viewport.at_top()) {message_fetch.maybe_load_older_messages({msg_list: current_msg_list,- show_loading: exports.show_loading_older,- hide_loading: exports.hide_loading_older,});}diff --git a/static/js/narrow.js b/static/js/narrow.jsindex ecc6181c078..21374f25cba 100644--- a/static/js/narrow.js+++ b/static/js/narrow.js@@ -299,8 +299,6 @@ exports.activate = function (raw_operators, opts) {id_info: id_info,select_offset: then_select_offset,});- } else {- message_scroll.show_loading_older();}// Put the narrow operators in the URL fragment.