channel_folders: Include channels whose folder names also match search.

This commit is contained in:
Aman Agrawal
2025-08-12 21:16:08 +05:30
committed by Tim Abbott
parent 7731eacac2
commit 9d05c80e63
3 changed files with 50 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ import {FoldDict} from "./fold_dict.ts";
import type {ChannelFolderUpdateEvent} from "./server_event_types.ts";
import type {StateData, channel_folder_schema} from "./state_data.ts";
import * as stream_data from "./stream_data.ts";
import * as util from "./util.ts";
export type ChannelFolder = z.infer<typeof channel_folder_schema>;
@@ -102,3 +103,20 @@ export function get_stream_ids_in_folder(folder_id: number): number[] {
const streams = stream_data.get_unsorted_subs().filter((sub) => sub.folder_id === folder_id);
return streams.map((sub) => sub.stream_id);
}
export function get_channels_in_folders_matching_seach_term_in_folder_name(
search_term: string,
): number[] {
const channel_folders = get_channel_folders();
const matching_channel_folders = util.filter_by_word_prefix_match(
channel_folders,
search_term,
(channel_folder) => channel_folder.name,
);
const channel_ids: number[] = [];
for (const channel_folder of matching_channel_folders) {
channel_ids.push(...get_stream_ids_in_folder(channel_folder.id));
}
return channel_ids;
}

View File

@@ -147,6 +147,19 @@ export function sort_groups(stream_ids: number[], search_term: string): StreamLi
stream_ids.push(current_channel_id);
}
// If the channel folder matches the search term, include all channels
// of that folder.
if (user_settings.web_left_sidebar_show_channel_folders && search_term) {
stream_ids = [
...new Set([
...stream_ids,
...channel_folders.get_channels_in_folders_matching_seach_term_in_folder_name(
search_term,
),
]),
];
}
const pinned_section: StreamListSection = {
id: "pinned-streams",
folder_id: null,

View File

@@ -101,4 +101,23 @@ run_test("basics", () => {
stream_3.stream_id,
]);
assert.deepEqual(channel_folders.get_stream_ids_in_folder(backend_folder.id), []);
// Tests for get_channels_in_folders_matching_seach_term_in_folder_name
// Should match 'Frontend' folder and return its streams
assert.deepEqual(
channel_folders.get_channels_in_folders_matching_seach_term_in_folder_name("Front"),
[stream_2.stream_id, stream_4.stream_id],
);
// Should match 'Backend' folder and return no streams
assert.deepEqual(
channel_folders.get_channels_in_folders_matching_seach_term_in_folder_name("Back"),
[],
);
// Should match no folder and return empty array
assert.deepEqual(
channel_folders.get_channels_in_folders_matching_seach_term_in_folder_name("Nonexistent"),
[],
);
});