mattermost-mobile/app/screens/channel_notification_preferences/index.ts
Elias Nahum edef4ec4a3
Update libraries and dependencies (#7678)
* update js dependencies

* update react-native libraries

* update watermelonDB

* update RN to 0.72.7

* update fastlane

* fix remove_markdown/at_mention import

* update mattermost libraries

* update fastlane deps

* remove haptic-feedback patch

* update okhttp to 4.12.0 and patch netinfo to accurately identify VPN connections

* create ImaegStyles intersection type
2023-11-25 07:46:13 +08:00

73 lines
2.6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {withDatabase, withObservables} from '@nozbe/watermelondb/react';
import {of as of$} from 'rxjs';
import {switchMap, combineLatestWith} from 'rxjs/operators';
import {NotificationLevel} from '@constants';
import {observeChannel, observeChannelSettings, observeIsMutedSetting} from '@queries/servers/channel';
import {observeHasGMasDMFeature} from '@queries/servers/features';
import {observeIsCRTEnabled} from '@queries/servers/thread';
import {observeCurrentUser} from '@queries/servers/user';
import {isTypeDMorGM} from '@utils/channel';
import {getNotificationProps} from '@utils/user';
import ChannelNotificationPreferences from './channel_notification_preferences';
import type {WithDatabaseArgs} from '@typings/database/database';
type EnhancedProps = WithDatabaseArgs & {
channelId: string;
}
const enhanced = withObservables([], ({channelId, database}: EnhancedProps) => {
const settings = observeChannelSettings(database, channelId);
const isCRTEnabled = observeIsCRTEnabled(database);
const isMuted = observeIsMutedSetting(database, channelId);
const notifyProps = observeCurrentUser(database).pipe(switchMap((u) => of$(getNotificationProps(u))));
const channelType = observeChannel(database, channelId).pipe(switchMap((c) => of$(c?.type)));
const hasGMasDMFeature = observeHasGMasDMFeature(database);
const notifyLevel = settings.pipe(
switchMap((s) => of$(s?.notifyProps.push || NotificationLevel.DEFAULT)),
);
const notifyThreadReplies = settings.pipe(
switchMap((s) => of$(s?.notifyProps.push_threads)),
);
const defaultLevel = notifyProps.pipe(
switchMap((n) => of$(n?.push)),
combineLatestWith(hasGMasDMFeature, channelType),
switchMap(([v, hasFeature, cType]) => {
const shouldShowwithGMasDMBehavior = hasFeature && isTypeDMorGM(cType);
let defaultLevelToUse = v;
if (shouldShowwithGMasDMBehavior) {
if (v === NotificationLevel.MENTION) {
defaultLevelToUse = NotificationLevel.ALL;
}
}
return of$(defaultLevelToUse);
}),
);
const defaultThreadReplies = notifyProps.pipe(
switchMap((n) => of$(n?.push_threads)),
);
return {
isCRTEnabled,
isMuted,
notifyLevel,
notifyThreadReplies,
defaultLevel,
defaultThreadReplies,
channelType,
hasGMasDMFeature,
};
});
export default withDatabase(enhanced(ChannelNotificationPreferences));