import {useCallback} from 'react' import {View} from 'react-native' import {Trans, useLingui} from '@lingui/react/macro' import {type NativeStackScreenProps} from '@react-navigation/native-stack' import {type CommonNavigatorParams} from '#/lib/routes/types' import {useUpdateActorDeclaration} from '#/state/queries/messages/actor-declaration' import {useProfileQuery} from '#/state/queries/profile' import {useSession} from '#/state/session' import {ExportCarDialog} from '#/screens/Settings/components/ExportCarDialog' import {atoms as a, useTheme} from '#/alf' import {AgeRestrictedScreen} from '#/components/ageAssurance/AgeRestrictedScreen' import {useAgeAssuranceCopy} from '#/components/ageAssurance/useAgeAssuranceCopy' import * as Dialog from '#/components/Dialog' import {Divider} from '#/components/Divider' import {resolveAllowGroupInvites} from '#/components/dms/util' import * as Toggle from '#/components/forms/Toggle' import {Bell_Stroke2_Corner0_Rounded as BellIcon} from '#/components/icons/Bell' import {Car_Stroke2_Corner2_Rounded as CarIcon} from '#/components/icons/Car' import {ChevronRight_Stroke2_Corner0_Rounded as ChevronRightIcon} from '#/components/icons/Chevron' import * as Layout from '#/components/Layout' import * as Toast from '#/components/Toast' import {Text} from '#/components/Typography' import {useAnalytics} from '#/analytics' import {IS_NATIVE} from '#/env' import {useBackgroundNotificationPreferences} from '../../../modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider' type AllowIncoming = 'all' | 'none' | 'following' type Props = NativeStackScreenProps export function MessagesSettingsScreen(props: Props) { const {t: l} = useLingui() const aaCopy = useAgeAssuranceCopy() return ( ) } export function MessagesSettingsScreenInner({}: Props) { const t = useTheme() const {t: l} = useLingui() const ax = useAnalytics() const {currentAccount} = useSession() const {data: profile} = useProfileQuery({ did: currentAccount!.did, }) const {preferences, setPref} = useBackgroundNotificationPreferences() const exportCarControl = Dialog.useDialogControl() const isGroupChatEnabled = ax.features.enabled(ax.features.GroupChatsEnable) const allowMessagesFromOptions: {name: AllowIncoming; label: string}[] = [ { name: 'all', label: l({context: 'allow messages from', message: `Everyone`}), }, { name: 'following', label: l({context: 'allow messages from', message: `Users I follow`}), }, { name: 'none', label: l({context: 'allow messages from', message: `No one`}), }, ] const allowGroupInvitesFromOptions: {name: AllowIncoming; label: string}[] = [ { name: 'all', label: l({context: 'allow group chat invites from', message: `Everyone`}), }, { name: 'following', label: l({ context: 'allow group chat invites from', message: `Users I follow`, }), }, { name: 'none', label: l({context: 'allow group chat invites from', message: `No one`}), }, ] const {mutate: updateDeclaration} = useUpdateActorDeclaration({ onError: () => { Toast.show(l`Failed to update settings`, { type: 'error', }) }, }) const onSelectMessagesFrom = useCallback( (keys: string[]) => { const key = keys[0] if (!key) return updateDeclaration({allowIncoming: key as AllowIncoming}) }, [updateDeclaration], ) const onSelectGroupInvitesFrom = useCallback( (keys: string[]) => { const key = keys[0] if (!key) return updateDeclaration({allowGroupInvites: key as AllowIncoming}) }, [updateDeclaration], ) const onSelectSoundSetting = useCallback( (selected: boolean) => { setPref('playSoundChat', selected) }, [setPref], ) return ( Chat Settings Allow direct messages from You can continue ongoing conversations regardless of which setting you choose. {allowMessagesFromOptions.map(option => ( {({selected}) => ( )} ))} {isGroupChatEnabled ? ( <> Allow group chat invites from You can continue ongoing conversations regardless of which setting you choose. {allowGroupInvitesFromOptions.map(option => ( {({selected}) => ( )} ))} ) : null} {IS_NATIVE && ( <> Notification sounds )} { exportCarControl.open() }}> Export my chat data ) }