forked from Ivasoft/mattermost-mobile
Do not show favorites category if it only contain archived channels (#6881)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -2,14 +2,23 @@
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import withObservables from '@nozbe/with-observables';
|
||||
import {switchMap} from 'rxjs/operators';
|
||||
|
||||
import {observeConfigBooleanValue} from '@queries/servers/system';
|
||||
|
||||
import CategoryHeader from './header';
|
||||
|
||||
import type CategoryModel from '@typings/database/models/servers/category';
|
||||
|
||||
const enhanced = withObservables(['category'], ({category}: {category: CategoryModel}) => ({
|
||||
category,
|
||||
hasChannels: category.hasChannels,
|
||||
}));
|
||||
const enhanced = withObservables(['category'], ({category}: {category: CategoryModel}) => {
|
||||
const canViewArchived = observeConfigBooleanValue(category.database, 'ExperimentalViewArchivedChannels');
|
||||
|
||||
return {
|
||||
category,
|
||||
hasChannels: canViewArchived.pipe(
|
||||
switchMap((canView) => category.observeHasChannels(canView)),
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
export default enhanced(CategoryHeader);
|
||||
|
||||
@@ -58,7 +58,7 @@ declare class CategoryModel extends Model {
|
||||
@lazy myChannels: Query<MyChannelModel>;
|
||||
|
||||
/** hasChannels : Whether the category has any channels */
|
||||
@lazy hasChannels: Observable<boolean>;
|
||||
observeHasChannels(canViewArchived: boolean): Observable<boolean>;
|
||||
|
||||
/** toCategoryWithChannels returns a map of the Category with an array of ordered channel ids */
|
||||
toCategoryWithChannels(): Promise<CategoryWithChannels>;
|
||||
|
||||
Reference in New Issue
Block a user