diff --git a/app/screens/find_channels/filtered_list/index.ts b/app/screens/find_channels/filtered_list/index.ts index e887cb4ce..93d0bbc3d 100644 --- a/app/screens/find_channels/filtered_list/index.ts +++ b/app/screens/find_channels/filtered_list/index.ts @@ -37,14 +37,15 @@ const enhanced = withObservables(['term'], ({database, term}: EnhanceProps) => { switchMap((matchStart) => { return retrieveChannels(database, matchStart.flat(), true); }), - switchMap((myChannels) => removeChannelsFromArchivedTeams(myChannels, teamIds)), + combineLatestWith(teamIds), + switchMap(([myChannels, tmIds]) => of$(removeChannelsFromArchivedTeams(myChannels, tmIds))), ); const channelsMatch = joinedChannelsMatch.pipe( combineLatestWith(directChannelsMatch), switchMap((matched) => retrieveChannels(database, matched.flat(), true)), - switchMap((myChannels) => removeChannelsFromArchivedTeams(myChannels, teamIds)), - + combineLatestWith(teamIds), + switchMap(([myChannels, tmIds]) => of$(removeChannelsFromArchivedTeams(myChannels, tmIds))), ); const archivedChannels = observeArchiveChannelsByTerm(database, term, MAX_RESULTS).pipe( diff --git a/app/screens/find_channels/unfiltered_list/index.ts b/app/screens/find_channels/unfiltered_list/index.ts index cf5407cd9..433b47da2 100644 --- a/app/screens/find_channels/unfiltered_list/index.ts +++ b/app/screens/find_channels/unfiltered_list/index.ts @@ -4,7 +4,7 @@ import {withDatabase} from '@nozbe/watermelondb/DatabaseProvider'; import withObservables from '@nozbe/with-observables'; import {Observable, of as of$} from 'rxjs'; -import {switchMap} from 'rxjs/operators'; +import {combineLatestWith, switchMap} from 'rxjs/operators'; import {queryMyRecentChannels} from '@queries/servers/channel'; import {queryJoinedTeams} from '@queries/servers/team'; @@ -26,7 +26,8 @@ const enhanced = withObservables([], ({database}: WithDatabaseArgs) => { const recentChannels = queryMyRecentChannels(database, MAX_CHANNELS). observeWithColumns(['last_viewed_at']).pipe( switchMap((myChannels) => retrieveChannels(database, myChannels, true)), - switchMap((myChannels) => removeChannelsFromArchivedTeams(myChannels, teamIds)), + combineLatestWith(teamIds), + switchMap(([myChannels, tmIds]) => of$(removeChannelsFromArchivedTeams(myChannels, tmIds))), ); return { diff --git a/app/screens/find_channels/utils.ts b/app/screens/find_channels/utils.ts index 5065ac411..7c559711c 100644 --- a/app/screens/find_channels/utils.ts +++ b/app/screens/find_channels/utils.ts @@ -2,7 +2,7 @@ // See LICENSE.txt for license information. import {Database, Q} from '@nozbe/watermelondb'; -import {Observable, of as of$, switchMap} from 'rxjs'; +import {of as of$} from 'rxjs'; import {MM_TABLES} from '@constants/database'; @@ -26,17 +26,11 @@ export const retrieveChannels = (database: Database, myChannels: MyChannelModel[ return of$([]); }; -export const removeChannelsFromArchivedTeams = (recentChannels: ChannelModel[], teamIds: Observable>) => { - return teamIds.pipe( - // eslint-disable-next-line max-nested-callbacks - switchMap((teamIdsSet) => - // eslint-disable-next-line max-nested-callbacks - of$(recentChannels.filter((channel) => { - if (!channel.teamId) { - return true; - } - return teamIdsSet.has(channel.teamId); - })), - ), - ); +export const removeChannelsFromArchivedTeams = (recentChannels: ChannelModel[], teamIds: Set) => { + return recentChannels.filter((channel) => { + if (!channel.teamId) { + return true; + } + return teamIds.has(channel.teamId); + }); };