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: Move function to stream_list to avoid circular imports.

Aman Agrawalabd54396de45
diff --git a/web/src/stream_list.ts b/web/src/stream_list.ts
index 7113f659372..78d1c3848fe 100644
--- a/web/src/stream_list.ts
+++ b/web/src/stream_list.ts
@@ -363,8 +363,48 @@ export function build_stream_list(force_rerender: boolean): void {
$("#streams_list").toggleClass("is_searching", ui_util.get_left_sidebar_search_term() !== "");
}
+export function mention_counts_by_section(): Map<
+ string,
+ {
+ has_mentions: boolean;
+ has_unmuted_mentions: boolean;
+ }
+> {
+ const mentions_map = new Map<
+ string,
+ {
+ has_mentions: boolean;
+ has_unmuted_mentions: boolean;
+ }
+ >();
+ const streams_with_mentions = unread.get_channels_with_unread_mentions();
+ const streams_with_unmuted_mentions = unread.get_channels_with_unmuted_mentions();
+ for (const stream_id of streams_with_mentions) {
+ const section_id = stream_list_sort.current_section_id_for_stream(stream_id);
+ if (section_id === undefined) {
+ continue;
+ }
+ if (!mentions_map.has(section_id)) {
+ mentions_map.set(section_id, {
+ has_mentions: false,
+ has_unmuted_mentions: false,
+ });
+ }
+ mentions_map.get(section_id)!.has_mentions = true;
+ }
+ for (const stream_id of streams_with_unmuted_mentions) {
+ const section_id = stream_list_sort.current_section_id_for_stream(stream_id);
+ if (section_id === undefined) {
+ continue;
+ }
+ mentions_map.get(section_id)!.has_unmuted_mentions = true;
+ }
+
+ return mentions_map;
+}
+
export let update_stream_section_mention_indicators = function (): void {
- const mentions = unread.mention_counts_by_section();
+ const mentions = mention_counts_by_section();
for (const section of stream_list_sort.section_ids()) {
const $header = $(`#stream-list-${section}-container .stream-list-subsection-header`);
const mentions_for_section = mentions.get(section) ?? {
diff --git a/web/src/unread.ts b/web/src/unread.ts
index 535e3343ec7..41628561aba 100644
--- a/web/src/unread.ts
+++ b/web/src/unread.ts
@@ -14,7 +14,6 @@ import type {
unread_direct_message_info_schema,
} from "./state_data.ts";
import * as stream_data from "./stream_data.ts";
-import * as stream_list_sort from "./stream_list_sort.ts";
import type {TopicHistoryEntry} from "./stream_topic_history.ts";
import * as sub_store from "./sub_store.ts";
import {user_settings} from "./user_settings.ts";
@@ -1013,6 +1012,14 @@ export function num_unread_for_topic(stream_id: number, topic_name: string): num
return unread_topic_counter.get(stream_id, topic_name);
}
+export function get_channels_with_unread_mentions(): Set<number> {
+ return unread_topic_counter.get_streams_with_unread_mentions();
+}
+
+export function get_channels_with_unmuted_mentions(): Set<number> {
+ return unread_topic_counter.get_streams_with_unmuted_mentions();
+}
+
export function stream_has_any_unread_mentions(stream_id: number): boolean {
// This function is somewhat inefficient and thus should not be
// called in loops, since runs in O(total unread mentions) time.
@@ -1027,46 +1034,6 @@ export function stream_has_any_unmuted_mentions(stream_id: number): boolean {
return streams_with_mentions.has(stream_id);
}
-export function mention_counts_by_section(): Map<
- string,
- {
- has_mentions: boolean;
- has_unmuted_mentions: boolean;
- }
-> {
- const mentions_map = new Map<
- string,
- {
- has_mentions: boolean;
- has_unmuted_mentions: boolean;
- }
- >();
- const streams_with_mentions = unread_topic_counter.get_streams_with_unread_mentions();
- const streams_with_unmuted_mentions = unread_topic_counter.get_streams_with_unmuted_mentions();
- for (const stream_id of streams_with_mentions) {
- const section_id = stream_list_sort.current_section_id_for_stream(stream_id);
- if (section_id === undefined) {
- continue;
- }
- if (!mentions_map.has(section_id)) {
- mentions_map.set(section_id, {
- has_mentions: false,
- has_unmuted_mentions: false,
- });
- }
- mentions_map.get(section_id)!.has_mentions = true;
- }
- for (const stream_id of streams_with_unmuted_mentions) {
- const section_id = stream_list_sort.current_section_id_for_stream(stream_id);
- if (section_id === undefined) {
- continue;
- }
- mentions_map.get(section_id)!.has_unmuted_mentions = true;
- }
-
- return mentions_map;
-}
-
export function topic_has_any_unread_mentions(stream_id: number, topic: string): boolean {
// Because this function is called in a loop for every displayed
// Recent Conversations row, it's important for it to run in O(1) time.