add verification to dms
This commit is contained in:
@@ -3,14 +3,18 @@ import {View} from 'react-native'
|
|||||||
import {AppBskyActorDefs} from '@atproto/api'
|
import {AppBskyActorDefs} from '@atproto/api'
|
||||||
import {msg} from '@lingui/macro'
|
import {msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
import {useNavigation} from '@react-navigation/native'
|
||||||
|
|
||||||
|
import {useEmail} from '#/lib/hooks/useEmail'
|
||||||
|
import {NavigationProp} from '#/lib/routes/types'
|
||||||
import {logEvent} from '#/lib/statsig/statsig'
|
import {logEvent} from '#/lib/statsig/statsig'
|
||||||
import {useMaybeConvoForUser} from '#/state/queries/messages/get-convo-for-members'
|
import {useMaybeConvoForUser} from '#/state/queries/messages/get-convo-for-members'
|
||||||
import {atoms as a, useTheme} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {ButtonIcon} from '#/components/Button'
|
import {Button, ButtonIcon} from '#/components/Button'
|
||||||
import {canBeMessaged} from '#/components/dms/util'
|
import {canBeMessaged} from '#/components/dms/util'
|
||||||
import {Message_Stroke2_Corner0_Rounded as Message} from '#/components/icons/Message'
|
import {Message_Stroke2_Corner0_Rounded as Message} from '#/components/icons/Message'
|
||||||
import {Link} from '#/components/Link'
|
import {useDialogControl} from '../Dialog'
|
||||||
|
import {VerifyEmailDialog} from '../dialogs/VerifyEmailDialog'
|
||||||
|
|
||||||
export function MessageProfileButton({
|
export function MessageProfileButton({
|
||||||
profile,
|
profile,
|
||||||
@@ -19,15 +23,30 @@ export function MessageProfileButton({
|
|||||||
}) {
|
}) {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
|
const navigation = useNavigation<NavigationProp>()
|
||||||
|
const {needsEmailVerification} = useEmail()
|
||||||
|
const verifyEmailControl = useDialogControl()
|
||||||
|
|
||||||
const {data: convo, isPending} = useMaybeConvoForUser(profile.did)
|
const {data: convo, isPending} = useMaybeConvoForUser(profile.did)
|
||||||
|
|
||||||
const onPress = React.useCallback(() => {
|
const onPress = React.useCallback(() => {
|
||||||
|
if (!convo?.id) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needsEmailVerification) {
|
||||||
|
console.log('open')
|
||||||
|
verifyEmailControl.open()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (convo && !convo.lastMessage) {
|
if (convo && !convo.lastMessage) {
|
||||||
logEvent('chat:create', {logContext: 'ProfileHeader'})
|
logEvent('chat:create', {logContext: 'ProfileHeader'})
|
||||||
}
|
}
|
||||||
logEvent('chat:open', {logContext: 'ProfileHeader'})
|
logEvent('chat:open', {logContext: 'ProfileHeader'})
|
||||||
}, [convo])
|
|
||||||
|
navigation.navigate('MessagesConversation', {conversation: convo.id})
|
||||||
|
}, [needsEmailVerification, verifyEmailControl, convo, navigation])
|
||||||
|
|
||||||
if (isPending) {
|
if (isPending) {
|
||||||
// show pending state based on declaration
|
// show pending state based on declaration
|
||||||
@@ -53,18 +72,26 @@ export function MessageProfileButton({
|
|||||||
|
|
||||||
if (convo) {
|
if (convo) {
|
||||||
return (
|
return (
|
||||||
<Link
|
<>
|
||||||
testID="dmBtn"
|
<Button
|
||||||
size="small"
|
accessibilityRole="button"
|
||||||
color="secondary"
|
testID="dmBtn"
|
||||||
variant="solid"
|
size="small"
|
||||||
shape="round"
|
color="secondary"
|
||||||
label={_(msg`Message ${profile.handle}`)}
|
variant="solid"
|
||||||
to={`/messages/${convo.id}`}
|
shape="round"
|
||||||
style={[a.justify_center]}
|
label={_(msg`Message ${profile.handle}`)}
|
||||||
onPress={onPress}>
|
style={[a.justify_center]}
|
||||||
<ButtonIcon icon={Message} size="md" />
|
onPress={onPress}>
|
||||||
</Link>
|
<ButtonIcon icon={Message} size="md" />
|
||||||
|
</Button>
|
||||||
|
<VerifyEmailDialog
|
||||||
|
reasonText={_(
|
||||||
|
msg`Before you may message another user, you must first verify your email.`,
|
||||||
|
)}
|
||||||
|
control={verifyEmailControl}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import React, {useCallback} from 'react'
|
|||||||
import {msg} from '@lingui/macro'
|
import {msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
|
import {useEmail} from '#/lib/hooks/useEmail'
|
||||||
import {logEvent} from '#/lib/statsig/statsig'
|
import {logEvent} from '#/lib/statsig/statsig'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
import {useGetConvoForMembers} from '#/state/queries/messages/get-convo-for-members'
|
import {useGetConvoForMembers} from '#/state/queries/messages/get-convo-for-members'
|
||||||
@@ -9,6 +10,8 @@ import {FAB} from '#/view/com/util/fab/FAB'
|
|||||||
import * as Toast from '#/view/com/util/Toast'
|
import * as Toast from '#/view/com/util/Toast'
|
||||||
import {useTheme} from '#/alf'
|
import {useTheme} from '#/alf'
|
||||||
import * as Dialog from '#/components/Dialog'
|
import * as Dialog from '#/components/Dialog'
|
||||||
|
import {useDialogControl} from '#/components/Dialog'
|
||||||
|
import {VerifyEmailDialog} from '#/components/dialogs/VerifyEmailDialog'
|
||||||
import {PlusLarge_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus'
|
import {PlusLarge_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus'
|
||||||
import {SearchablePeopleList} from './SearchablePeopleList'
|
import {SearchablePeopleList} from './SearchablePeopleList'
|
||||||
|
|
||||||
@@ -21,6 +24,8 @@ export function NewChat({
|
|||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
|
const {needsEmailVerification} = useEmail()
|
||||||
|
const verifyEmailControl = useDialogControl()
|
||||||
|
|
||||||
const {mutate: createChat} = useGetConvoForMembers({
|
const {mutate: createChat} = useGetConvoForMembers({
|
||||||
onSuccess: data => {
|
onSuccess: data => {
|
||||||
@@ -48,7 +53,13 @@ export function NewChat({
|
|||||||
<>
|
<>
|
||||||
<FAB
|
<FAB
|
||||||
testID="newChatFAB"
|
testID="newChatFAB"
|
||||||
onPress={control.open}
|
onPress={() => {
|
||||||
|
if (needsEmailVerification) {
|
||||||
|
verifyEmailControl.open()
|
||||||
|
} else {
|
||||||
|
control.open()
|
||||||
|
}
|
||||||
|
}}
|
||||||
icon={<Plus size="lg" fill={t.palette.white} />}
|
icon={<Plus size="lg" fill={t.palette.white} />}
|
||||||
accessibilityRole="button"
|
accessibilityRole="button"
|
||||||
accessibilityLabel={_(msg`New chat`)}
|
accessibilityLabel={_(msg`New chat`)}
|
||||||
@@ -62,6 +73,13 @@ export function NewChat({
|
|||||||
onSelectChat={onCreateChat}
|
onSelectChat={onCreateChat}
|
||||||
/>
|
/>
|
||||||
</Dialog.Outer>
|
</Dialog.Outer>
|
||||||
|
|
||||||
|
<VerifyEmailDialog
|
||||||
|
reasonText={_(
|
||||||
|
msg`Before you may message another user, you must first verify your email.`,
|
||||||
|
)}
|
||||||
|
control={verifyEmailControl}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user