Files
zulip/static/js/fetch_status.js
Ryan Rehman e0b1fdb81c message view: Show home view bottom loading indicators.
As explained in 67053ff479,
multiple message fetches may be taking place at the same time.
So some other narrows / the home message list's indicator might
get shown for the current narrow.

This commit moves the updation of the indicators display logic
to the `fetch_status` API.
Now the `loading_newer_messages_indicator` gets displayed along
with the `loading_newer` = true updation for that narrow's message
list, i.e. just before we send the API request. But only if the
message list we are fetching matches with our current message list.

The same indicator is hidden similarly, along with the
`loading_older` = false updation for that narrow's message list,
i.e. just after the success response is recieved. But only if
the message list whose data we recieved  matches with our current
message list.

Also the indicators are hidden everytime we activate narrow
or deactivate narrow (`home_msg_list`). And on entering
`narrow.activate` we fetch for it's messages so they get
displayed again, if need be.
This is the reason `message_scroll.hide_indicators();` was
moved to a location above `fetch_messages`.

Fixes #15374.
2020-06-15 22:25:41 -07:00

61 lines
1.4 KiB
JavaScript

const FetchStatus = function () {
const self = {};
let loading_older = false;
let loading_newer = false;
let found_oldest = false;
let found_newest = false;
let history_limited = false;
self.start_older_batch = function () {
loading_older = true;
};
self.finish_older_batch = function (opts) {
loading_older = false;
found_oldest = opts.found_oldest;
history_limited = opts.history_limited;
};
self.can_load_older_messages = function () {
return !loading_older && !found_oldest;
};
self.has_found_oldest = function () {
return found_oldest;
};
self.history_limited = function () {
return history_limited;
};
self.start_newer_batch = function (opts) {
loading_newer = true;
if (opts.update_loading_indicator) {
message_scroll.show_loading_newer();
}
};
self.finish_newer_batch = function (opts) {
loading_newer = false;
found_newest = opts.found_newest;
if (opts.update_loading_indicator) {
message_scroll.hide_loading_newer();
}
};
self.can_load_newer_messages = function () {
return !loading_newer && !found_newest;
};
self.has_found_newest = function () {
return found_newest;
};
return self;
};
module.exports = FetchStatus;
window.FetchStatus = FetchStatus;