85f2ff39a7
The lex client throws XrpcResponseError, which is not an XRPCError subclass, so the old per-method error classes generated by @atproto/api no longer match. Those instanceof checks compile fine but silently stop firing, degrading every typed chat failure to the generic fallback message. Narrow against the method schema instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import {useLingui} from '@lingui/react/macro'
|
|
import {StackActions, useNavigation} from '@react-navigation/native'
|
|
|
|
import {type NavigationProp} from '#/lib/routes/types'
|
|
import {isNetworkError} from '#/lib/strings/errors'
|
|
import {matchXrpcError} from '#/lib/xrpc-error'
|
|
import {useLeaveConvo} from '#/state/queries/messages/leave-conversation'
|
|
import {type DialogOuterProps} from '#/components/Dialog'
|
|
import * as Prompt from '#/components/Prompt'
|
|
import * as Toast from '#/components/Toast'
|
|
import {IS_NATIVE} from '#/env'
|
|
import {chat} from '#/lexicons'
|
|
|
|
export function LeaveConvoPrompt({
|
|
control,
|
|
convoId,
|
|
currentScreen,
|
|
hasMessages = true,
|
|
}: {
|
|
control: DialogOuterProps['control']
|
|
convoId: string
|
|
currentScreen: 'list' | 'conversation'
|
|
hasMessages?: boolean
|
|
}) {
|
|
const {t: l} = useLingui()
|
|
const navigation = useNavigation<NavigationProp>()
|
|
|
|
const {mutate: leaveConvo} = useLeaveConvo(convoId, {
|
|
onMutate: () => {
|
|
if (currentScreen === 'conversation') {
|
|
navigation.dispatch(
|
|
StackActions.replace('Messages', IS_NATIVE ? {animation: 'pop'} : {}),
|
|
)
|
|
}
|
|
},
|
|
onError: error => {
|
|
let errorMessage = l`Could not leave chat`
|
|
if (isNetworkError(error)) {
|
|
errorMessage = l`A network error occurred. Please check your internet connection.`
|
|
} else {
|
|
switch (matchXrpcError(error, chat.bsky.convo.leaveConvo)) {
|
|
case 'InvalidConvo':
|
|
errorMessage = l`Conversation not found.`
|
|
break
|
|
case 'OwnerCannotLeave':
|
|
errorMessage = l`Owner must lock the group before leaving.`
|
|
break
|
|
}
|
|
}
|
|
Toast.show(errorMessage, {type: 'error'})
|
|
},
|
|
})
|
|
|
|
return (
|
|
<Prompt.Basic
|
|
control={control}
|
|
title={l`Leave conversation`}
|
|
description={
|
|
hasMessages
|
|
? l`Are you sure you want to leave this conversation? Your messages will be deleted for you, but not for the other participants.`
|
|
: l`Are you sure you want to leave this conversation?`
|
|
}
|
|
confirmButtonCta={l`Leave`}
|
|
confirmButtonColor="negative"
|
|
onConfirm={() => leaveConvo()}
|
|
/>
|
|
)
|
|
}
|