Do not show favorites category if it only contain archived channels (#6881)

This commit is contained in:
Elias Nahum
2022-12-20 11:42:50 +02:00
committed by GitHub
parent b01a5bfab8
commit 0f1a29e2da
3 changed files with 26 additions and 10 deletions

View File

@@ -104,11 +104,18 @@ export default class CategoryModel extends Model implements CategoryInterface {
Q.sortBy('last_post_at', Q.desc),
);
/** hasChannels : Returns a boolean indicating if the category has channels */
@lazy hasChannels = this.categoryChannels.observeCount().pipe(
map((c) => c > 0),
distinctUntilChanged(),
);
observeHasChannels = (canViewArchived: boolean) => {
return this.channels.observeWithColumns(['delete_at']).pipe(
map((channels) => {
if (canViewArchived) {
return channels.length > 0;
}
return channels.filter((c) => c.deleteAt === 0).length > 0;
}),
distinctUntilChanged(),
);
};
toCategoryWithChannels = async (): Promise<CategoryWithChannels> => {
const categoryChannels = await this.categoryChannels.fetch();