Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
recent_view: Keep a topic's row until its delayed visibility update.
Aman Agrawaldd2ef339f6ed
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.tsindex 494afd08123..fe4e7435e50 100644--- a/web/src/recent_view_ui.ts+++ b/web/src/recent_view_ui.ts@@ -110,6 +110,7 @@ const ls = localstorage();let filters = new Set<string>();let dropdown_filters = new Set<string>();+const pending_topic_visibility_updates = new Set<string>();let folder_filter_value: number = folder_dropdown_widget.FOLDER_FILTERS.ANY_FOLDER_DROPDOWN_OPTION;let folder_filter_dropdown_widget: dropdown_widget.DropdownWidget | undefined;@@ -216,6 +217,7 @@ export function clear_for_tests(): void {dropdown_filters.clear();folder_filter_value = folder_dropdown_widget.FOLDER_FILTERS.ANY_FOLDER_DROPDOWN_OPTION;recent_view_data.conversations.clear();+ pending_topic_visibility_updates.clear();topics_widget = undefined;}@@ -1059,6 +1061,16 @@ export function filters_should_hide_row(topic_data: ConversationData): boolean {}}+ if (+ pending_topic_visibility_updates.size > 0 &&+ pending_topic_visibility_updates.has(get_conversation_key(topic_data))+ ) {+ // The scheduled update adds or removes the row. Until then, a+ // popover may be anchored on the row, and the widget would count+ // a newly listed conversation as rendered without giving it one.+ return get_topic_row(topic_data).length === 0;+ }+const folder_filters = folder_dropdown_widget.FOLDER_FILTERS;if (folder_filter_value !== folder_filters.ANY_FOLDER_DROPDOWN_OPTION) {// When a folder filter is active, hide all DMs.@@ -1272,7 +1284,9 @@ export function schedule_topic_visibility_update(return false;}+ pending_topic_visibility_updates.add(key);setTimeout(() => {+ pending_topic_visibility_updates.delete(key);inplace_rerender(key);}, delay_ms);return true;diff --git a/web/tests/recent_view.test.cjs b/web/tests/recent_view.test.cjsindex 35ca2a891ed..53400509270 100644--- a/web/tests/recent_view.test.cjs+++ b/web/tests/recent_view.test.cjs@@ -1110,6 +1110,38 @@ test("a topic's visibility update rerenders its row after the delay", ({overrideassert.deepEqual(rerendered_keys, [get_topic_key(stream1, topic1)]);});+test("a topic's row stays listed until its delayed visibility update", () => {+ // The filters would hide the muted topic at once, but a popover may+ // be anchored on its row.+ show_recent_view_with_messages();+ const muted_conversation = conversation_for(topic7);+ assert.ok(rt.filters_should_hide_row(muted_conversation));++ rt.schedule_topic_visibility_update(stream1, topic7, 500);+ clock.tick(499);+ assert.ok(!rt.filters_should_hide_row(muted_conversation));++ clock.tick(1);+ assert.ok(rt.filters_should_hide_row(muted_conversation));+});++test("a conversation without a row stays unlisted until its visibility update", () => {+ // The update gives a topic that is no longer hidden its row. A+ // rerender before that must not list the topic: the widget counts a+ // row for every conversation it lists in its rendered range.+ show_recent_view_with_messages();+ const conversation = conversation_for(topic1);+ stub_no_row_for(get_topic_key(stream1, topic1));+ assert.ok(!rt.filters_should_hide_row(conversation));++ rt.schedule_topic_visibility_update(stream1, topic1, 500);+ clock.tick(499);+ assert.ok(rt.filters_should_hide_row(conversation));++ clock.tick(1);+ assert.ok(!rt.filters_should_hide_row(conversation));+});+test("basic assertions", ({mock_template}) => {rt.clear_for_tests();rt.set_filters_for_tests();