Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
left_sidebar: Implement new unread_count logic for muted stream.
Hardik Dharmani6f1b8fe340fe
diff --git a/web/src/stream_list.js b/web/src/stream_list.jsindex 286a53728f9..6523f86a625 100644--- a/web/src/stream_list.js+++ b/web/src/stream_list.js@@ -33,7 +33,11 @@ export let stream_cursor;let has_scrolled = false;-export function update_count_in_dom($stream_li, count, stream_has_any_unread_mention_messages) {+export function update_count_in_dom(+ $stream_li,+ stream_counts,+ stream_has_any_unread_mention_messages,+) {// The subscription_block properly excludes the topic list,// and it also has sensitive margins related to whether the// count is there or not.@@ -45,10 +49,38 @@ export function update_count_in_dom($stream_li, count, stream_has_any_unread_menstream_has_any_unread_mention_messages,);- if (count === 0) {+ // Here we set the count and compute the values of two classes:+ // .stream-with-count is used for the layout CSS to know whether+ // to leave space for the unread count, and has-unmuted-unreads is+ // used in muted streams to set the fading correctly to indicate+ // those are unread+ if (stream_counts.unmuted_count > 0 && !stream_counts.stream_is_muted) {+ // Normal stream, has unmuted unreads; display normally.+ ui_util.update_unread_count_in_dom($subscription_block, stream_counts.unmuted_count);+ $subscription_block.addClass("stream-with-count");+ $subscription_block.removeClass("has-unmuted-unreads");+ } else if (stream_counts.unmuted_count > 0 && stream_counts.stream_is_muted) {+ // Muted stream, has unmuted unreads.+ ui_util.update_unread_count_in_dom($subscription_block, stream_counts.unmuted_count);+ $subscription_block.addClass("stream-with-count");+ $subscription_block.addClass("has-unmuted-unreads");+ } else if (stream_counts.muted_count > 0 && stream_counts.stream_is_muted) {+ // Muted stream, only muted unreads.+ ui_util.update_unread_count_in_dom($subscription_block, stream_counts.muted_count);+ $subscription_block.addClass("stream-with-count");+ $subscription_block.removeClass("has-unmuted-unreads");+ } else if (stream_counts.muted_count > 0 && !stream_counts.stream_is_muted) {+ // Normal stream, only muted unreads: display nothing. The+ // current thinking is displaying those counts with muted+ // styling would be more distracting than helpful.+ ui_util.update_unread_count_in_dom($subscription_block, 0);+ $subscription_block.removeClass("has-unmuted-unreads");$subscription_block.removeClass("stream-with-count");} else {- $subscription_block.addClass("stream-with-count");+ // No unreads: display nothing.+ ui_util.update_unread_count_in_dom($subscription_block, 0);+ $subscription_block.removeClass("has-unmuted-unreads");+ $subscription_block.removeClass("stream-with-count");}}diff --git a/web/src/unread.js b/web/src/unread.jsindex 08b459fa87a..7cac920f75b 100644--- a/web/src/unread.js+++ b/web/src/unread.js@@ -274,17 +274,29 @@ class UnreadTopicCounter {continue;}- let stream_count = 0;+ let unmuted_count = 0;+ let muted_count = 0;for (const [topic, msgs] of per_stream_bucketer) {const topic_count = msgs.size;- if (!user_topics.is_topic_muted(stream_id, topic)) {- stream_count += topic_count;++ if (user_topics.is_topic_unmuted(stream_id, topic)) {+ unmuted_count += topic_count;+ } else if (user_topics.is_topic_muted(stream_id, topic)) {+ muted_count += topic_count;+ } else if (sub.is_muted) {+ muted_count += topic_count;+ } else {+ unmuted_count += topic_count;}}- res.stream_count.set(stream_id, stream_count);- if (!stream_data.is_muted(stream_id)) {- res.stream_unread_messages += stream_count;- }++ res.stream_count.set(stream_id, {+ unmuted_count,+ muted_count,+ stream_is_muted: sub.is_muted,+ });++ res.stream_unread_messages += unmuted_count;}return res;@@ -332,8 +344,6 @@ class UnreadTopicCounter {}get_stream_count(stream_id) {- let stream_count = 0;-const per_stream_bucketer = this.bucketer.get_bucket(stream_id);if (!per_stream_bucketer) {@@ -341,12 +351,26 @@ class UnreadTopicCounter {}const sub = sub_store.get(stream_id);+ let unmuted_count = 0;+ let muted_count = 0;for (const [topic, msgs] of per_stream_bucketer) {- if (sub && !user_topics.is_topic_muted(stream_id, topic)) {- stream_count += msgs.size;+ const topic_count = msgs.size;++ if (user_topics.is_topic_unmuted(stream_id, topic)) {+ unmuted_count += topic_count;+ } else if (user_topics.is_topic_muted(stream_id, topic)) {+ muted_count += topic_count;+ } else if (sub.is_muted) {+ muted_count += topic_count;+ } else {+ unmuted_count += topic_count;}}-+ const stream_count = {+ unmuted_count,+ muted_count,+ stream_is_muted: sub.is_muted,+ };return stream_count;}diff --git a/web/styles/left_sidebar.css b/web/styles/left_sidebar.cssindex ea3c3612609..0a088eedb7b 100644--- a/web/styles/left_sidebar.css+++ b/web/styles/left_sidebar.css@@ -346,6 +346,12 @@ ul.filters {opacity: 0.5;}+ .has-unmuted-unreads {+ .unread_count {+ opacity: 1;+ }+ }+& li.unmuted_topic {color: hsl(0deg 0% 20%);@@ -366,6 +372,12 @@ ul.filters {.unread_count {opacity: 0.75;}++ .has-unmuted-unreads {+ .unread_count {+ opacity: 1;+ }+ }}& li.muted_topic {diff --git a/web/tests/stream_list.test.js b/web/tests/stream_list.test.jsindex 4081206a70b..4b3366be85c 100644--- a/web/tests/stream_list.test.js+++ b/web/tests/stream_list.test.js@@ -29,7 +29,11 @@ const scroll_util = mock_esm("../src/scroll_util", {});mock_esm("../src/ui", {get_scroll_element: ($element) => $element});mock_esm("../src/unread", {- num_unread_for_stream: () => num_unread_for_stream,+ num_unread_for_stream: () => ({+ unmuted_count: num_unread_for_stream,+ stream_is_muted: false,+ muted_count: 0,+ }),stream_has_any_unread_mentions: () => stream_has_any_unread_mentions,});diff --git a/web/tests/unread.test.js b/web/tests/unread.test.jsindex 6bc15824bfb..770d6581868 100644--- a/web/tests/unread.test.js+++ b/web/tests/unread.test.js@@ -227,9 +227,9 @@ test("muting", () => {unread.process_loaded_messages([message]);let counts = unread.get_counts();- assert.equal(counts.stream_count.get(stream_id), 1);+ assert.equal(counts.stream_count.get(stream_id).unmuted_count, 1);assert.equal(counts.home_unread_messages, 1);- assert.equal(unread.num_unread_for_stream(stream_id), 1);+ assert.equal(unread.num_unread_for_stream(stream_id).unmuted_count, 1);assert.deepEqual(unread.get_msg_ids_for_stream(stream_id), [message.id]);test_notifiable_count(counts.home_unread_messages, 0);@@ -239,9 +239,9 @@ test("muting", () => {user_topics.all_visibility_policies.MUTED,);counts = unread.get_counts();- assert.equal(counts.stream_count.get(stream_id), 0);+ assert.equal(counts.stream_count.get(stream_id).unmuted_count, 0);assert.equal(counts.home_unread_messages, 0);- assert.equal(unread.num_unread_for_stream(stream_id), 0);+ assert.equal(unread.num_unread_for_stream(stream_id).unmuted_count, 0);assert.deepEqual(unread.get_msg_ids_for_stream(stream_id), []);test_notifiable_count(counts.home_unread_messages, 0);@@ -345,7 +345,7 @@ test("home_messages", () => {counts = unread.get_counts();assert.equal(counts.home_unread_messages, 1);- assert.equal(counts.stream_count.get(stream_id), 1);+ assert.equal(counts.stream_count.get(stream_id).unmuted_count, 1);test_notifiable_count(counts.home_unread_messages, 0);unread.mark_as_read(message.id);counts = unread.get_counts();