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.

left_sidebar: Fix unread counts showing for muted channels.

opmkumarb5fc39044e86
diff --git a/web/src/settings_data.ts b/web/src/settings_data.ts
index 9bc7b1b77f9..2d6afa18777 100644
--- a/web/src/settings_data.ts
+++ b/web/src/settings_data.ts
@@ -278,7 +278,10 @@ export function user_can_delete_own_message(): boolean {
);
}
-export function should_mask_unread_count(sub_muted: boolean): boolean {
+export function should_mask_unread_count(
+ sub_muted: boolean,
+ unmuted_unread_count: number,
+): boolean {
if (
user_settings.web_stream_unreads_count_display_policy ===
settings_config.web_stream_unreads_count_display_policy_values.no_streams.code
@@ -286,11 +289,17 @@ export function should_mask_unread_count(sub_muted: boolean): boolean {
return true;
}
+ /* istanbul ignore next */
if (
user_settings.web_stream_unreads_count_display_policy ===
settings_config.web_stream_unreads_count_display_policy_values.unmuted_streams.code
) {
- return sub_muted;
+ if (!sub_muted) {
+ // This policy always shows unread counts in non-muted channels.
+ return false;
+ }
+ // For muted channels, it depends whether any unmuted unreads exist.
+ return unmuted_unread_count === 0;
}
return false;
diff --git a/web/src/stream_list.ts b/web/src/stream_list.ts
index 9e257808f63..57d73e6b66b 100644
--- a/web/src/stream_list.ts
+++ b/web/src/stream_list.ts
@@ -190,6 +190,12 @@ export let update_count_in_dom = (
$subscription_block.removeClass("has-only-muted-unreads");
$subscription_block.removeClass("stream-with-count");
}
+
+ toggle_hide_unread_counts(
+ $subscription_block,
+ stream_counts.stream_is_muted,
+ stream_counts.unmuted_count,
+ );
};
export function rewire_update_count_in_dom(value: typeof update_count_in_dom): void {
@@ -476,7 +482,6 @@ function build_stream_sidebar_li(sub: StreamSubscription): JQuery {
is_web_public: sub.is_web_public,
color: sub.color,
pin_to_top: sub.pin_to_top,
- hide_unread_count: settings_data.should_mask_unread_count(is_muted),
can_post_messages,
is_empty_topic_only_channel: stream_data.is_empty_topic_only_channel(sub.stream_id),
};
@@ -641,18 +646,32 @@ export function update_dom_with_unread_counts(counts: FullUnreadCountsData): voi
}
}
+function toggle_hide_unread_counts(
+ $subscription_block: JQuery,
+ sub_muted: boolean,
+ unmuted_unread_counts: number,
+): void {
+ const hide_count = settings_data.should_mask_unread_count(sub_muted, unmuted_unread_counts);
+
+ $subscription_block.toggleClass("hide_unread_counts", hide_count);
+}
+
export function update_dom_unread_counts_visibility(): void {
+ // TODO: It's not obviously why this function exists; can't we
+ // just do a full left sidebar rebuild?
for (const stream of stream_sidebar.rows.values()) {
const $subscription_block = stream.get_li().find(".subscription_block");
const is_muted = stream_data.is_muted(stream.sub.stream_id);
- const hide_count = settings_data.should_mask_unread_count(is_muted);
-
- if (hide_count) {
- $subscription_block.addClass("hide_unread_counts");
- } else {
- $subscription_block.removeClass("hide_unread_counts");
- }
+ // Technically, we just need to know if there's at least one
+ // unmuted unread here, so this could be optimized by using a
+ // faster `unread.ts` API optimized to compute just the set of
+ // channels with at least one unmuted unread.
+ //
+ // That optimization is inessential as long as this function
+ // is only called when changing a global personal setting.
+ const stream_counts = unread.unread_count_info_for_stream(stream.sub.stream_id);
+ toggle_hide_unread_counts($subscription_block, is_muted, stream_counts.unmuted_count);
}
}
diff --git a/web/styles/left_sidebar.css b/web/styles/left_sidebar.css
index 045706a3742..56300638e68 100644
--- a/web/styles/left_sidebar.css
+++ b/web/styles/left_sidebar.css
@@ -172,16 +172,6 @@
}
}
- .has-unmuted-unreads.hide_unread_counts {
- .masked_unread_count {
- display: none;
- }
-
- .unread_count {
- display: inline;
- }
- }
-
.toggle_stream_mute {
margin-right: 3px;
opacity: 0.5;
diff --git a/web/templates/stream_sidebar_row.hbs b/web/templates/stream_sidebar_row.hbs
index 9c9187edf7a..16ff540dfd1 100644
--- a/web/templates/stream_sidebar_row.hbs
+++ b/web/templates/stream_sidebar_row.hbs
@@ -2,7 +2,7 @@
<li class="narrow-filter{{#if is_muted}} out_of_home_view{{/if}}" data-stream-id="{{id}}">
<div class="bottom_left_row">
- <a href="{{url}}" class="subscription_block selectable_sidebar_block {{#if hide_unread_count}}hide_unread_counts{{/if}}">
+ <a href="{{url}}" class="subscription_block selectable_sidebar_block">
<span class="stream-privacy-original-color-{{id}} stream-privacy filter-icon" style="color: {{color}}">
{{> stream_privacy . }}
diff --git a/web/tests/stream_list.test.cjs b/web/tests/stream_list.test.cjs
index 40134b5c81a..6ea0399ac72 100644
--- a/web/tests/stream_list.test.cjs
+++ b/web/tests/stream_list.test.cjs
@@ -343,6 +343,7 @@ const testSub = {
subscribed: true,
is_recently_active: true,
can_send_message_group: everyone_group.id,
+ is_muted: true,
};
const announceSub = {
@@ -733,7 +734,6 @@ test_ui("rename_stream", ({mock_template, override}) => {
is_web_public: undefined,
color: payload.color,
pin_to_top: true,
- hide_unread_count: true,
can_post_messages: true,
is_empty_topic_only_channel: false,
});