From 107559b1bb5b41e23b41e16deea55d1b76c9db55 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Tue, 3 Dec 2024 15:04:51 +0530 Subject: [PATCH] message_fetch: Fetch again if the view is not scrollable. If the initial fetch for the narrow didn't return enough data for the view to becomes scrollable, we should try to populate the narrow with more messages. --- web/src/message_fetch.ts | 3 ++- web/src/message_viewport.ts | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/web/src/message_fetch.ts b/web/src/message_fetch.ts index d9f58383ed..b6b1fae7fc 100644 --- a/web/src/message_fetch.ts +++ b/web/src/message_fetch.ts @@ -17,6 +17,7 @@ import type {MessageListData} from "./message_list_data.ts"; import * as message_lists from "./message_lists.ts"; import {raw_message_schema} from "./message_store.ts"; import * as message_util from "./message_util.ts"; +import * as message_viewport from "./message_viewport.ts"; import * as narrow_banner from "./narrow_banner.ts"; import {page_params} from "./page_params.ts"; import * as people from "./people.ts"; @@ -176,7 +177,7 @@ function process_result(data: MessageFetchResponse, opts: MessageFetchOptions): // the messages we requested, and all of them are in muted // topics, but there are older messages for this stream that // we need to ask the server for. - message_lists.current.visibly_empty() + (message_lists.current.visibly_empty() || !message_viewport.can_scroll()) ) { const looking_for_new_msgs = opts.num_after > 0; const looking_for_old_msgs = opts.num_before > 0; diff --git a/web/src/message_viewport.ts b/web/src/message_viewport.ts index c921242e10..f534169319 100644 --- a/web/src/message_viewport.ts +++ b/web/src/message_viewport.ts @@ -542,6 +542,11 @@ export function maybe_scroll_to_selected(): void { } } +export function can_scroll(): boolean { + const full_height = util.the($scroll_container).scrollHeight; + return full_height > window.innerHeight; +} + export function initialize(): void { // This handler must be placed before all resize handlers in our application $(window).on("resize", () => {