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.

stream_list: Update unread counts when building the sidebar.

Evy Kassirer259fd250ede5
diff --git a/web/src/stream_list.ts b/web/src/stream_list.ts
index c4e4f34ec0e..60e6e8c696c 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 8b626a2e266..894b3436ede 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 `<stub-section-${section.id}>`;
});
+ 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, [$("<devel-sidebar-row-stub>"), $("<Rome-sidebar-row-stub>")]);
});
-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();