Merge pull request #7505 from mattermost/MM-53849-mobile-hide-channels-from-archived-teams

MM-53849 - hide channels from archived teams during channels search
This commit is contained in:
Pablo Andrés Vélez Vidal 2023-08-23 10:44:05 +02:00 committed by GitHub
commit ccdab81d7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 4 deletions

View file

@ -12,7 +12,7 @@ import {observeConfigValue, observeCurrentTeamId} from '@queries/servers/system'
import {queryJoinedTeams} from '@queries/servers/team';
import {observeIsCRTEnabled} from '@queries/servers/thread';
import {observeTeammateNameDisplay} from '@queries/servers/user';
import {retrieveChannels} from '@screens/find_channels/utils';
import {removeChannelsFromArchivedTeams, retrieveChannels} from '@screens/find_channels/utils';
import FilteredList, {MAX_RESULTS} from './filtered_list';
@ -37,11 +37,15 @@ const enhanced = withObservables(['term'], ({database, term}: EnhanceProps) => {
switchMap((matchStart) => {
return retrieveChannels(database, matchStart.flat(), true);
}),
combineLatestWith(teamIds),
switchMap(([myChannels, tmIds]) => of$(removeChannelsFromArchivedTeams(myChannels, tmIds))),
);
const channelsMatch = joinedChannelsMatch.pipe(
combineLatestWith(directChannelsMatch),
switchMap((matched) => retrieveChannels(database, matched.flat(), true)),
combineLatestWith(teamIds),
switchMap(([myChannels, tmIds]) => of$(removeChannelsFromArchivedTeams(myChannels, tmIds))),
);
const archivedChannels = observeArchiveChannelsByTerm(database, term, MAX_RESULTS).pipe(

View file

@ -3,12 +3,12 @@
import {withDatabase} from '@nozbe/watermelondb/DatabaseProvider';
import withObservables from '@nozbe/with-observables';
import {of as of$} from 'rxjs';
import {switchMap} from 'rxjs/operators';
import {Observable, of as of$} from 'rxjs';
import {combineLatestWith, switchMap} from 'rxjs/operators';
import {queryMyRecentChannels} from '@queries/servers/channel';
import {queryJoinedTeams} from '@queries/servers/team';
import {retrieveChannels} from '@screens/find_channels/utils';
import {removeChannelsFromArchivedTeams, retrieveChannels} from '@screens/find_channels/utils';
import UnfilteredList from './unfiltered_list';
@ -18,10 +18,16 @@ const MAX_CHANNELS = 20;
const enhanced = withObservables([], ({database}: WithDatabaseArgs) => {
const teamsCount = queryJoinedTeams(database).observeCount();
const teamIds: Observable<Set<string>> = queryJoinedTeams(database).observe().pipe(
// eslint-disable-next-line max-nested-callbacks
switchMap((teams) => of$(new Set(teams.map((t) => t.id)))),
);
const recentChannels = queryMyRecentChannels(database, MAX_CHANNELS).
observeWithColumns(['last_viewed_at']).pipe(
switchMap((myChannels) => retrieveChannels(database, myChannels, true)),
combineLatestWith(teamIds),
switchMap(([myChannels, tmIds]) => of$(removeChannelsFromArchivedTeams(myChannels, tmIds))),
);
return {

View file

@ -25,3 +25,12 @@ export const retrieveChannels = (database: Database, myChannels: MyChannelModel[
return of$([]);
};
export const removeChannelsFromArchivedTeams = (recentChannels: ChannelModel[], teamIds: Set<string>) => {
return recentChannels.filter((channel) => {
if (!channel.teamId) {
return true;
}
return teamIds.has(channel.teamId);
});
};