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.

topic_list: Show muted unread counts in muted streams.

Tim Abbott7425079814d6
diff --git a/web/src/topic_list.js b/web/src/topic_list.js
index 23009a65157..8cde577d590 100644
--- a/web/src/topic_list.js
+++ b/web/src/topic_list.js
@@ -81,11 +81,16 @@ export function keyed_topic_li(conversation) {
};
}
-export function more_li(more_topics_unreads, more_topics_have_unread_mention_messages) {
+export function more_li(
+ more_topics_unreads,
+ more_topics_have_unread_mention_messages,
+ more_topics_unread_count_muted,
+) {
const render = () =>
render_more_topics({
more_topics_unreads,
more_topics_have_unread_mention_messages,
+ more_topics_unread_count_muted,
});
const eq = (other) => other.more_items && more_topics_unreads === other.more_topics_unreads;
@@ -147,7 +152,13 @@ export class TopicListWidget {
if (spinner) {
nodes.push(spinner_li());
} else if (!is_showing_all_possible_topics) {
- nodes.push(more_li(more_topics_unreads, more_topics_have_unread_mention_messages));
+ nodes.push(
+ more_li(
+ more_topics_unreads,
+ more_topics_have_unread_mention_messages,
+ list_info.more_topics_unread_count_muted,
+ ),
+ );
}
const dom = vdom.ul({
diff --git a/web/src/topic_list_data.js b/web/src/topic_list_data.js
index b6a73dbc936..5a2b67744ac 100644
--- a/web/src/topic_list_data.js
+++ b/web/src/topic_list_data.js
@@ -69,13 +69,15 @@ function choose_topics(stream_id, topic_names, zoomed, topic_choice_state) {
const show_topic = should_show_topic(topic_choice_state.topics_selected);
if (!show_topic) {
if (!is_topic_muted) {
- // The "more topics" unread count, like
- // stream-level counts, only counts messages
- // on unmuted topics.
- topic_choice_state.more_topics_unreads += num_unread;
+ topic_choice_state.more_topics_unmuted_unreads += num_unread;
if (contains_unread_mention) {
topic_choice_state.more_topics_have_unread_mention_messages = true;
}
+ } else {
+ topic_choice_state.more_topics_muted_unreads += num_unread;
+ if (contains_unread_mention) {
+ topic_choice_state.more_topics_have_muted_unread_mention_messages = true;
+ }
}
continue;
}
@@ -105,8 +107,10 @@ export function get_list_info(stream_id, zoomed, search_term) {
const topic_choice_state = {
items: [],
topics_selected: 0,
- more_topics_unreads: 0,
+ more_topics_muted_unreads: 0,
+ more_topics_unmuted_unreads: 0,
more_topics_have_unread_mention_messages: false,
+ more_topics_have_muted_unread_mention_messages: false,
active_topic: narrow_state.topic()?.toLowerCase(),
topics_with_unread_mentions: unread.get_topics_with_unread_mentions(stream_id),
};
@@ -132,11 +136,32 @@ export function get_list_info(stream_id, zoomed, search_term) {
choose_topics(stream_id, topic_names, zoomed, topic_choice_state);
}
+ if (
+ topic_choice_state.more_topics_unmuted_unreads === 0 &&
+ topic_choice_state.more_topics_muted_unreads > 0 &&
+ stream_muted
+ ) {
+ // For muted streams, if the only unreads are in muted topics,
+ // we have a muted styling "more topics" row.
+ return {
+ items: topic_choice_state.items,
+ num_possible_topics: topic_names.length,
+ more_topics_unreads: topic_choice_state.more_topics_muted_unreads,
+ more_topics_have_unread_mention_messages:
+ topic_choice_state.more_topics_have_muted_unread_mention_messages,
+ more_topics_unread_count_muted: true,
+ };
+ }
return {
items: topic_choice_state.items,
num_possible_topics: topic_names.length,
- more_topics_unreads: topic_choice_state.more_topics_unreads,
+ more_topics_unreads: topic_choice_state.more_topics_unmuted_unreads,
more_topics_have_unread_mention_messages:
- topic_choice_state.more_topics_have_unread_mention_messages,
+ // Because mentions are important, and get displayed in the
+ // overall summary, we display the mention indicator even if
+ // they are in muted streams.
+ topic_choice_state.more_topics_have_unread_mention_messages ||
+ topic_choice_state.more_topics_have_muted_unread_mention_messages,
+ more_topics_unread_count_muted: false,
};
}
diff --git a/web/styles/left_sidebar.css b/web/styles/left_sidebar.css
index 1b1476944b8..b239bf72b8a 100644
--- a/web/styles/left_sidebar.css
+++ b/web/styles/left_sidebar.css
@@ -342,6 +342,13 @@ ul.filters {
margin-bottom: 10px;
}
+ /* This is a noop in the current design, because unread counts for
+ muted streams have the same opacity, but the logic is here to
+ be explicit and because the design may change in the future. */
+ .more_topic_unreads_muted_only .unread_count {
+ opacity: 0.5;
+ }
+
& li.muted_topic,
li.out_of_home_view {
color: hsl(0deg 0% 20% / 50%);
diff --git a/web/templates/more_topics.hbs b/web/templates/more_topics.hbs
index a0afa7a0ffa..d64d69b44c2 100644
--- a/web/templates/more_topics.hbs
+++ b/web/templates/more_topics.hbs
@@ -1,4 +1,6 @@
-<li class="topic-list-item show-more-topics bottom_left_row {{#unless more_topics_unreads}}zero-topic-unreads{{/unless}}">
+<li class="topic-list-item show-more-topics bottom_left_row
+ {{#unless more_topics_unreads}}zero-topic-unreads{{/unless}}
+ {{#if more_topics_unread_count_muted}}more_topic_unreads_muted_only{{/if}}">
<span class='topic-box'>
<a class="topic-name" tabindex="0">{{t "more topics" }}</a>
{{#if more_topics_have_unread_mention_messages}}
diff --git a/web/tests/topic_list_data.test.js b/web/tests/topic_list_data.test.js
index 11169c54543..ea5a42e4fd4 100644
--- a/web/tests/topic_list_data.test.js
+++ b/web/tests/topic_list_data.test.js
@@ -61,6 +61,7 @@ test("get_list_info w/real stream_topic_history", ({override}) => {
items: [],
more_topics_have_unread_mention_messages: false,
more_topics_unreads: 0,
+ more_topics_unread_count_muted: false,
num_possible_topics: 0,
});
@@ -269,6 +270,7 @@ test("get_list_info unreads", ({override}) => {
assert.equal(list_info.more_topics_unreads, 3);
assert.equal(list_info.more_topics_have_unread_mention_messages, true);
assert.equal(list_info.num_possible_topics, 16);
+ assert.equal(list_info.more_topics_unread_count_muted, false);
assert.deepEqual(
list_info.items.map((li) => li.topic_name),
@@ -287,4 +289,87 @@ test("get_list_info unreads", ({override}) => {
"topic 12",
],
);
+
+ // Now test with topics 4/8/9, all the ones with unreads, being muted.
+ override(user_topics, "is_topic_muted", (stream_id, topic_name) => {
+ assert.equal(stream_id, general.stream_id);
+ return ["topic 4", "topic 8", "topic 9"].includes(topic_name);
+ });
+ list_info = get_list_info();
+ assert.equal(list_info.items.length, 12);
+ assert.equal(list_info.more_topics_unreads, 3);
+ // Topic 14 now makes it above the "more topics" fold.
+ assert.equal(list_info.more_topics_have_unread_mention_messages, false);
+ assert.equal(list_info.num_possible_topics, 16);
+ assert.equal(list_info.more_topics_unread_count_muted, true);
+ assert.deepEqual(
+ list_info.items.map((li) => li.topic_name),
+ [
+ "topic 5",
+ "topic 0",
+ "topic 1",
+ "topic 2",
+ "topic 3",
+ "topic 6",
+ "topic 7",
+ "topic 10",
+ "topic 11",
+ "topic 12",
+ "topic 13",
+ "topic 14",
+ ],
+ );
+
+ add_unreads_with_mention("topic 8", 1);
+ list_info = get_list_info();
+ assert.equal(list_info.items.length, 12);
+ assert.equal(list_info.more_topics_unreads, 4);
+ // Topic 8's new mention gets counted here.
+ assert.equal(list_info.more_topics_have_unread_mention_messages, true);
+ assert.equal(list_info.num_possible_topics, 16);
+ assert.equal(list_info.more_topics_unread_count_muted, true);
+ assert.deepEqual(
+ list_info.items.map((li) => li.topic_name),
+ [
+ "topic 5",
+ "topic 0",
+ "topic 1",
+ "topic 2",
+ "topic 3",
+ "topic 6",
+ "topic 7",
+ "topic 10",
+ "topic 11",
+ "topic 12",
+ "topic 13",
+ "topic 14",
+ ],
+ );
+
+ // Adding an additional older unmuted topic with unreads should
+ // result in just the unmuted unreads being counted.
+ add_unreads("topic 15", 15);
+ list_info = get_list_info();
+ assert.equal(list_info.items.length, 12);
+ assert.equal(list_info.more_topics_unreads, 15);
+ assert.equal(list_info.more_topics_have_unread_mention_messages, true);
+ assert.equal(list_info.num_possible_topics, 16);
+ assert.equal(list_info.more_topics_unread_count_muted, false);
+ assert.deepEqual(
+ list_info.items.map((li) => li.topic_name),
+ [
+ "topic 5",
+ "topic 0",
+ "topic 1",
+ "topic 2",
+ "topic 3",
+ "topic 6",
+ "topic 7",
+ "topic 10",
+ "topic 11",
+ "topic 12",
+ "topic 13",
+ "topic 14",
+ ],
+ );
});