Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

message_scroll: Fix check for when to fetch new messages for the view.

Aman Agrawal24a167229dd3
diff --git a/web/src/message_list_view.js b/web/src/message_list_view.js
index 591405c8c66..5141a268349 100644
--- a/web/src/message_list_view.js
+++ b/web/src/message_list_view.js
@@ -1191,6 +1191,30 @@ export class MessageListView {
return true;
}
+ should_fetch_older_messages() {
+ const selected_idx = this.list.selected_idx();
+ // We fetch older messages when the user is near the top of the
+ // rendered message feed and there are older messages to fetch.
+ return (
+ // Make sure we have no cached message left to render.
+ this._render_win_start === 0 &&
+ selected_idx - this._render_win_start < this._RENDER_THRESHOLD &&
+ !this.list.data.fetch_status.has_found_oldest()
+ );
+ }
+
+ should_fetch_newer_messages() {
+ const selected_idx = this.list.selected_idx();
+ // We fetch new messages when the user is near the bottom of the
+ // rendered message feed and there are newer messages to fetch.
+ return (
+ // Make sure we have no cached message left to render.
+ this._render_win_end === this.list.num_items() &&
+ this._render_win_end - selected_idx <= this._RENDER_THRESHOLD &&
+ !this.list.data.fetch_status.has_found_newest()
+ );
+ }
+
maybe_rerender() {
const selected_idx = this.list.selected_idx();
diff --git a/web/src/message_scroll.js b/web/src/message_scroll.js
index c4b0b4299f4..a732c7dd94c 100644
--- a/web/src/message_scroll.js
+++ b/web/src/message_scroll.js
@@ -91,7 +91,7 @@ export function scroll_finished() {
message_scroll_state.set_update_selection_on_next_scroll(true);
}
- if (message_viewport.at_rendered_top()) {
+ if (message_lists.current.view.should_fetch_older_messages()) {
// Subtle note: While we've only checked that we're at the
// very top of the render window (i.e. there may be some more
// cached messages to render), it's a good idea to fetch
@@ -102,7 +102,7 @@ export function scroll_finished() {
});
}
- if (message_viewport.at_rendered_bottom()) {
+ if (message_lists.current.view.should_fetch_newer_messages()) {
// See the similar message_viewport.at_rendered_top block.
message_fetch.maybe_load_newer_messages({
msg_list: message_lists.current,
diff --git a/web/src/message_viewport.ts b/web/src/message_viewport.ts
index 9ae5bdc26d5..abf6202a98c 100644
--- a/web/src/message_viewport.ts
+++ b/web/src/message_viewport.ts
@@ -77,6 +77,7 @@ export function message_viewport_info(): MessageViewportInfo {
// the server are not considered.
export function at_rendered_bottom(): boolean {
const bottom = scrollTop() + height();
+ // This also includes bottom whitespace.
const full_height = $scroll_container[0].scrollHeight;
// We only know within a pixel or two if we're