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_data: Extract function to filter topics by search term.

Aman Agrawal6842615f1676
diff --git a/web/src/topic_list_data.ts b/web/src/topic_list_data.ts
index b62c701c38f..b46a5b5ab47 100644
--- a/web/src/topic_list_data.ts
+++ b/web/src/topic_list_data.ts
@@ -156,6 +156,21 @@ type TopicListInfo = {
more_topics_unread_count_muted: boolean;
};
+function filter_by_search_term(topic_names: string[], search_term: string): string[] {
+ if (search_term === "") {
+ return topic_names;
+ }
+
+ const word_separator_regex = /[\s/:_-]/; // Use -, _, :, / as word separators in addition to spaces.
+ const empty_string_topic_display_name = util.get_final_topic_display_name("");
+ return util.filter_by_word_prefix_match(
+ topic_names,
+ search_term,
+ (topic) => (topic === "" ? empty_string_topic_display_name : topic),
+ word_separator_regex,
+ );
+}
+
export function get_list_info(
stream_id: number,
zoomed: boolean,
@@ -188,14 +203,7 @@ export function get_list_info(
}
if (zoomed) {
- const word_separator_regex = /[\s/:_-]/; // Use -, _, :, / as word separators in addition to spaces.
- const empty_string_topic_display_name = util.get_final_topic_display_name("");
- topic_names = util.filter_by_word_prefix_match(
- topic_names,
- search_term,
- (topic) => (topic === "" ? empty_string_topic_display_name : topic),
- word_separator_regex,
- );
+ topic_names = filter_by_search_term(topic_names, search_term);
}
if (stream_muted && !zoomed) {