topic_list_data: Add support to filter empty string topic.

We show `realm_empty_topic_display_name` for empty string topics
in the left sidebar.

This commit makes it possible for users to search for
the `realm_empty_topic_display_name` value to filter out empty
string topics.
This commit is contained in:
Prakhar Pratyush
2025-02-21 12:29:39 +05:30
committed by Tim Abbott
parent 6ac9e3328e
commit eed056a591
2 changed files with 11 additions and 3 deletions

View File

@@ -189,10 +189,11 @@ 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,
(topic) => (topic === "" ? empty_string_topic_display_name : topic),
word_separator_regex,
);
}

View File

@@ -194,16 +194,23 @@ test("get_list_info w/real stream_topic_history", ({override}) => {
assert.equal(list_info.num_possible_topics, 11);
add_topic_message("After Brooklyn", 1008);
add_topic_message("Catering", 1009);
add_topic_message("Delhi", 1009);
// When topic search input is not empty, we show topics
// based on the search term.
const search_term = "b,c";
let search_term = "b,d";
list_info = get_list_info(zoomed, search_term);
assert.equal(list_info.items.length, 2);
assert.equal(list_info.more_topics_unreads, 0);
assert.equal(list_info.more_topics_have_unread_mention_messages, false);
assert.equal(list_info.num_possible_topics, 2);
// Verify empty string topic shows up for "general" search term.
search_term = "general";
list_info = get_list_info(zoomed, search_term);
assert.equal(list_info.items.length, 1);
assert.equal(list_info.items[0].topic_name, "");
assert.equal(list_info.items[0].topic_display_name, REALM_EMPTY_TOPIC_DISPLAY_NAME);
});
test("get_list_info unreads", ({override}) => {