From 259fd250ede51fcc925583b6a4ffd715a3ea7f7e Mon Sep 17 00:00:00 2001 From: Evy Kassirer Date: Sat, 9 Aug 2025 22:10:29 -0700 Subject: [PATCH] stream_list: Update unread counts when building the sidebar. This bug was introduced by 8817284f7a318384a65568095dcba887add6c15f which should have included this line. --- web/src/stream_list.ts | 13 +++++++++++-- web/tests/stream_list.test.cjs | 10 ++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/web/src/stream_list.ts b/web/src/stream_list.ts index c4e4f34ec0..60e6e8c696 100644 --- a/web/src/stream_list.ts +++ b/web/src/stream_list.ts @@ -355,8 +355,11 @@ export function build_stream_list(force_rerender: boolean): void { ); } } + // Rerendering can moving channels between folders and change heading unread counts. - left_sidebar_navigation_area.update_dom_with_unread_counts(unread.get_counts(), false); + const counts = unread.get_counts(); + left_sidebar_navigation_area.update_dom_with_unread_counts(counts, false); + update_dom_with_unread_counts(counts); sidebar_ui.update_unread_counts_visibility(); set_sections_states(); $("#streams_list").toggleClass("is_searching", get_search_term() !== ""); @@ -661,7 +664,7 @@ type SectionUnreadCount = { inactive_muted: number; }; -export function update_dom_with_unread_counts(counts: FullUnreadCountsData): void { +export let update_dom_with_unread_counts = function (counts: FullUnreadCountsData): void { // (1) Stream unread counts // counts.stream_count maps streams to counts for (const [stream_id, count] of counts.stream_count) { @@ -787,6 +790,12 @@ export function update_dom_with_unread_counts(counts: FullUnreadCountsData): voi unread_counts.inactive_muted, ); } +}; + +export function rewire_update_dom_with_unread_counts( + value: typeof update_dom_with_unread_counts, +): void { + update_dom_with_unread_counts = value; } function toggle_hide_unread_counts( diff --git a/web/tests/stream_list.test.cjs b/web/tests/stream_list.test.cjs index 8b626a2e26..894b3436ed 100644 --- a/web/tests/stream_list.test.cjs +++ b/web/tests/stream_list.test.cjs @@ -175,6 +175,7 @@ test_ui("create_sidebar_row", ({override, override_rewire, mock_template}) => { appended_sections.push(section.id); return ``; }); + override_rewire(stream_list, "update_dom_with_unread_counts", noop); const pinned_streams = []; $("#stream-list-pinned-streams").append = (stream) => { @@ -249,7 +250,9 @@ test_ui("create_sidebar_row", ({override, override_rewire, mock_template}) => { assert.ok(removed); }); -test_ui("pinned_streams_never_inactive", ({mock_template}) => { +test_ui("pinned_streams_never_inactive", ({mock_template, override_rewire}) => { + override_rewire(stream_list, "update_dom_with_unread_counts", noop); + stream_data.add_sub(devel); stream_data.add_sub(social); @@ -439,6 +442,7 @@ test_ui("zoom_in_and_zoom_out", ({mock_template}) => { }); test_ui("narrowing", ({override_rewire}) => { + override_rewire(stream_list, "update_dom_with_unread_counts", noop); initialize_stream_data(); topic_list.close = noop; @@ -565,6 +569,7 @@ test_ui("sort_streams", ({override_rewire}) => { }); test_ui("separators_only_pinned_and_dormant", ({override_rewire}) => { + override_rewire(stream_list, "update_dom_with_unread_counts", noop); // Get coverage on early-exit. stream_list.build_stream_list(); @@ -616,7 +621,8 @@ test_ui("separators_only_pinned_and_dormant", ({override_rewire}) => { assert.deepEqual(pinned_streams, [$(""), $("")]); }); -test_ui("rename_stream", ({mock_template, override}) => { +test_ui("rename_stream", ({mock_template, override, override_rewire}) => { + override_rewire(stream_list, "update_dom_with_unread_counts", noop); override(user_settings, "web_stream_unreads_count_display_policy", 3); override(current_user, "user_id", me.user_id); initialize_stream_data();