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.

recent_view: Render more rows when removals leave the table short.

Aman Agrawalbab4116b7c9f
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.ts
index b9c632f3406..580278cf4bc 100644
--- a/web/src/recent_view_ui.ts
+++ b/web/src/recent_view_ui.ts
@@ -1184,6 +1184,13 @@ function rerender_conversation_rows(row_keys: Set<string>): void {
}
}
}
+ // The widget renders more rows only on scroll, and removals can
+ // bring the end of the rows into view without one. Its own scroll
+ // check asks for rows from two thirds of the way down, which near
+ // the end of a long table would be hundreds of them at once.
+ while (!topics_widget.all_rendered() && views_util.is_bottom_padding_in_view()) {
+ topics_widget.render();
+ }
setTimeout(revive_current_focus, 0);
}
diff --git a/web/src/views_util.ts b/web/src/views_util.ts
index 9da52cc1c66..c593a165db0 100644
--- a/web/src/views_util.ts
+++ b/web/src/views_util.ts
@@ -217,3 +217,10 @@ export function is_scroll_position_for_render(): boolean {
const scroll_max = get_scroll_height_without_bottom_padding();
return scroll_position + window_height >= (2 / 3) * scroll_max;
}
+
+export let is_bottom_padding_in_view = (): boolean =>
+ window.scrollY + window.innerHeight >= get_scroll_height_without_bottom_padding();
+
+export function rewire_is_bottom_padding_in_view(value: typeof is_bottom_padding_in_view): void {
+ is_bottom_padding_in_view = value;
+}
diff --git a/web/tests/recent_view.test.cjs b/web/tests/recent_view.test.cjs
index dd4d176d366..4163c63ba7b 100644
--- a/web/tests/recent_view.test.cjs
+++ b/web/tests/recent_view.test.cjs
@@ -83,6 +83,8 @@ const ListWidget = mock_esm("../src/list_widget", {
hard_redraw: noop,
filter_and_sort: () => [],
+ get_current_list: () => [],
+ all_rendered: () => true,
replace_list_data(data) {
assert.notEqual(
expected_data_to_replace_in_list_widget,
@@ -226,6 +228,7 @@ const {buddy_list} = zrequire("buddy_list");
const activity_ui = zrequire("activity_ui");
const people = zrequire("people");
const rt = zrequire("recent_view_ui");
+const views_util = zrequire("views_util");
rt.set_hide_other_views(noop);
const recent_view_util = zrequire("recent_view_util");
const rt_data = zrequire("recent_view_data");
@@ -986,6 +989,34 @@ test("inplace_rerender updates one row the way a bulk rerender does", ({override
assert.equal(updates.length, 2);
});
+test("rerender renders more rows until they reach the bottom of the viewport", ({
+ override,
+ override_rewire,
+}) => {
+ show_recent_view_with_messages();
+ let batches_rendered = 0;
+ override(ListWidget, "render", () => {
+ batches_rendered += 1;
+ });
+
+ const batches_until_viewport_is_filled = 2;
+ override(ListWidget, "all_rendered", () => false);
+ override_rewire(
+ views_util,
+ "is_bottom_padding_in_view",
+ () => batches_rendered < batches_until_viewport_is_filled,
+ );
+ bulk_rerender([]);
+ assert.equal(batches_rendered, batches_until_viewport_is_filled);
+
+ batches_rendered = 0;
+ const batches_until_all_rendered = 3;
+ override_rewire(views_util, "is_bottom_padding_in_view", () => true);
+ override(ListWidget, "all_rendered", () => batches_rendered === batches_until_all_rendered);
+ bulk_rerender([]);
+ assert.equal(batches_rendered, batches_until_all_rendered);
+});
+
test("basic assertions", ({mock_template, override_rewire}) => {
override_rewire(rt, "inplace_rerender", noop);
rt.clear_for_tests();
diff --git a/web/tests/views_util.test.cjs b/web/tests/views_util.test.cjs
index e24d23889b6..9670ac1c95c 100644
--- a/web/tests/views_util.test.cjs
+++ b/web/tests/views_util.test.cjs
@@ -2,9 +2,13 @@
const assert = require("node:assert/strict");
-const {zrequire} = require("./lib/namespace.cjs");
+const {mock_jquery, zrequire} = require("./lib/namespace.cjs");
const {run_test} = require("./lib/test.cjs");
+// views_util reads the page's bottom padding from a CSS variable.
+const bottom_padding = 400;
+mock_jquery(() => ({css: () => `${bottom_padding}px`}));
+
const views_util = zrequire("views_util");
function make_row(top, height = 30) {
@@ -36,3 +40,17 @@ run_test("find_first_row_index_at_or_below", () => {
assert.equal(find_row_index(500), undefined);
assert.equal(views_util.find_first_row_index_at_or_below([], 145), undefined);
});
+
+run_test("is_bottom_padding_in_view", ({override}) => {
+ const viewport_bottom = 600;
+ const scroll_y = 100;
+ override(window, "scrollY", scroll_y);
+ override(window, "innerHeight", viewport_bottom - scroll_y);
+ const body = {scrollHeight: viewport_bottom + 1 + bottom_padding};
+ override(window, "document", {body});
+
+ // The rows end just below the bottom of the viewport, then at it.
+ assert.ok(!views_util.is_bottom_padding_in_view());
+ body.scrollHeight -= 1;
+ assert.ok(views_util.is_bottom_padding_in_view());
+});