refactor code based on pr comments
This commit is contained in:
parent
3b6dd923df
commit
109dd21a8a
3 changed files with 15 additions and 19 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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<Set<string>>) => {
|
||||
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<string>) => {
|
||||
return recentChannels.filter((channel) => {
|
||||
if (!channel.teamId) {
|
||||
return true;
|
||||
}
|
||||
return teamIds.has(channel.teamId);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue