mattermost-mobile/share_extension/components/content_view/options/index.ts
Elias Nahum 6eadc527bb
Gekidou Android share extension (#6803)
* Refactor app database queries to not require the app database as argument

* Android Share Extension and fix notifications prompt

* feedback review
2022-11-30 23:18:56 +02:00

50 lines
1.6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import withObservables from '@nozbe/with-observables';
import {of as of$, switchMap, combineLatestWith} from 'rxjs';
import {observeServerDisplayName} from '@queries/app/servers';
import {observeChannel} from '@queries/servers/channel';
import {observeTeam, queryJoinedTeams} from '@queries/servers/team';
import {observeServerHasChannels} from '@share/queries';
import Options from './options';
import type {WithDatabaseArgs} from '@typings/database/database';
type Props = WithDatabaseArgs & {
serverUrl?: string;
channelId?: string;
}
const enhanced = withObservables(['database', 'channelId', 'serverUrl'], ({database, channelId, serverUrl}: Props) => {
const channel = observeChannel(database, channelId || '');
const teamsCount = queryJoinedTeams(database).observeCount();
const team = channel.pipe(
switchMap((c) => (c?.teamId ? observeTeam(database, c.teamId) : of$(undefined))),
);
const channelDisplayName = channel.pipe(
combineLatestWith(team, teamsCount),
switchMap(([c, t, count]) => {
if (!c) {
return of$(undefined);
}
if (t) {
return of$(count > 1 ? `${c.displayName} (${t.displayName})` : c.displayName);
}
return of$(c.displayName);
}),
);
return {
channelDisplayName,
serverDisplayName: observeServerDisplayName(serverUrl || ''),
hasChannels: observeServerHasChannels(serverUrl || ''),
};
});
export default enhanced(Options);