import React, {useCallback, useEffect} from 'react' import {View} from 'react-native' import {ChatBskyActorDeclaration} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useUpdateActorDeclaration} from '#/state/queries/messages/actor-declaration' import {useProfileQuery} from '#/state/queries/profile' import {useSession} from '#/state/session' import * as Toast from '#/view/com/util/Toast' import {atoms as a, useTheme, web} from '#/alf' import {Button, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import * as Toggle from '#/components/forms/Toggle' import {Message_Stroke2_Corner0_Rounded} from '#/components/icons/Message' import {Text} from '#/components/Typography' export function MessagesNUX() { const control = Dialog.useDialogControl() const {currentAccount} = useSession() const {data: profile} = useProfileQuery({ did: currentAccount!.did, }) useEffect(() => { if (profile && typeof profile.associated?.chat === 'undefined') { const timeout = setTimeout(() => { control.open() }, 1000) return () => { clearTimeout(timeout) } } }, [profile, control]) if (!profile) return null return ( ) } function DialogInner({ chatDeclation, }: { chatDeclation?: ChatBskyActorDeclaration.Record }) { const control = Dialog.useDialogContext() const {_} = useLingui() const t = useTheme() const [initialized, setInitialzed] = React.useState(false) const {mutate: updateDeclaration} = useUpdateActorDeclaration({ onError: () => { Toast.show(_(msg`Failed to update settings`), 'xmark') }, }) const onSelectItem = useCallback( (keys: string[]) => { const key = keys[0] if (!key) return updateDeclaration(key as 'all' | 'none' | 'following') }, [updateDeclaration], ) useEffect(() => { if (!chatDeclation && !initialized) { updateDeclaration('following') setInitialzed(true) } }, [chatDeclation, updateDeclaration, initialized]) return ( Direct messages are here! Privately chat with other users. Who can message you? You can change this at any time. Everyone Users I follow No one ) }