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.

unread: Deduplicate the logic for adding up unread counts.

Hardik Dharmani8829190ec661
diff --git a/web/src/unread.js b/web/src/unread.js
index c0370ad9adc..645a25147e5 100644
--- a/web/src/unread.js
+++ b/web/src/unread.js
@@ -264,7 +264,7 @@ class UnreadTopicCounter {
const res = {};
res.stream_unread_messages = 0;
res.stream_count = new Map(); // hash by stream_id -> count
- for (const [stream_id, per_stream_bucketer] of this.bucketer) {
+ for (const [stream_id] of this.bucketer) {
// We track unread counts for streams that may be currently
// unsubscribed. Since users may re-subscribe, we don't
// completely throw away the data. But we do ignore it here,
@@ -274,29 +274,8 @@ class UnreadTopicCounter {
continue;
}
- 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_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, {
- unmuted_count,
- muted_count,
- stream_is_muted: sub.is_muted,
- });
-
- res.stream_unread_messages += unmuted_count;
+ res.stream_count.set(stream_id, this.get_stream_count(stream_id));
+ res.stream_unread_messages += res.stream_count.get(stream_id).unmuted_count;
}
return res;