channel_folders: Add help function to check if user has sub in folder.

This commit adds a function that returns true if user is subscribed
to a channel which is in a channel folder.
This commit is contained in:
Pratik Chanda
2025-08-12 01:10:54 +05:30
committed by Tim Abbott
parent f6eba9c396
commit 35896244d7
2 changed files with 17 additions and 0 deletions

View File

@@ -73,6 +73,18 @@ export function get_channel_folder_by_id(folder_id: number): ChannelFolder {
return channel_folder;
}
export function user_has_folders(): boolean {
const subscribed_subs = stream_data.subscribed_subs();
for (const sub of subscribed_subs) {
if (sub.folder_id) {
return true;
}
}
return false;
}
export function update(event: ChannelFolderUpdateEvent): void {
const folder_id = event.channel_folder_id;
const channel_folder = get_channel_folder_by_id(folder_id);

View File

@@ -89,6 +89,9 @@ run_test("basics", () => {
folder_id: frontend_folder.id,
});
stream_data.add_sub(stream_1);
assert.deepEqual(channel_folders.user_has_folders(), false);
stream_data.add_sub(stream_2);
stream_data.add_sub(stream_3);
stream_data.add_sub(stream_4);
@@ -120,4 +123,6 @@ run_test("basics", () => {
channel_folders.get_channels_in_folders_matching_seach_term_in_folder_name("Nonexistent"),
[],
);
assert.deepEqual(channel_folders.user_has_folders(), true);
});