An ATproto social media client -- with an independent Appview.
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

[Clipclops] Delete message in dialog (#3849)

* delete and copy

* add retry dialog if message send fails

* add layout animation

* fix `nextMessage` being incorrect

---------

Co-authored-by: Samuel Newman <mozzius@protonmail.com>

authored by

Hailey
Samuel Newman
and committed by
GitHub
c4160c25 7448c8f7

+36 -15
+24 -3
src/components/dms/MessageMenu.tsx
··· 1 1 import React from 'react' 2 - import {Pressable, View} from 'react-native' 2 + import {LayoutAnimation, Pressable, View} from 'react-native' 3 3 import * as Clipboard from 'expo-clipboard' 4 4 import {ChatBskyConvoDefs} from '@atproto-labs/api' 5 5 import {msg} from '@lingui/macro' 6 6 import {useLingui} from '@lingui/react' 7 7 8 + import {useChat} from 'state/messages' 9 + import {ConvoStatus} from 'state/messages/convo' 8 10 import {useSession} from 'state/session' 9 11 import * as Toast from '#/view/com/util/Toast' 10 12 import {atoms as a, useTheme} from '#/alf' ··· 31 33 const {_} = useLingui() 32 34 const t = useTheme() 33 35 const {currentAccount} = useSession() 36 + const chat = useChat() 34 37 const deleteControl = usePromptControl() 38 + const retryDeleteControl = usePromptControl() 35 39 36 40 const isFromSelf = message.sender?.did === currentAccount?.did 37 41 ··· 44 48 }, [_, message.text]) 45 49 46 50 const onDelete = React.useCallback(() => { 47 - // TODO delete the message 48 - }, []) 51 + if (chat.status !== ConvoStatus.Ready) return 52 + 53 + LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut) 54 + chat 55 + .deleteMessage(message.id) 56 + .then(() => Toast.show(_(msg`Message deleted`))) 57 + .catch(() => retryDeleteControl.open()) 58 + }, [_, chat, message.id, retryDeleteControl]) 49 59 50 60 const onReport = React.useCallback(() => { 51 61 // TODO report the message ··· 111 121 msg`Are you sure you want to delete this message? The message will be deleted for you, but not for other participants.`, 112 122 )} 113 123 confirmButtonCta={_(msg`Delete`)} 124 + confirmButtonColor="negative" 125 + onConfirm={onDelete} 126 + /> 127 + 128 + <Prompt.Basic 129 + control={retryDeleteControl} 130 + title={_(msg`Failed to delete message`)} 131 + description={_( 132 + msg`An error occurred while trying to delete the message. Please try again.`, 133 + )} 134 + confirmButtonCta={_(msg`Retry`)} 114 135 confirmButtonColor="negative" 115 136 onConfirm={onDelete} 116 137 />
+12 -12
src/state/messages/convo.ts
··· 92 92 convo: ChatBskyConvoDefs.ConvoView 93 93 error: undefined 94 94 isFetchingHistory: boolean 95 - deleteMessage: (messageId: string) => void 95 + deleteMessage: (messageId: string) => Promise<void> 96 96 sendMessage: ( 97 97 message: ChatBskyConvoSendMessage.InputSchema['message'], 98 98 ) => void ··· 104 104 convo: ChatBskyConvoDefs.ConvoView 105 105 error: undefined 106 106 isFetchingHistory: boolean 107 - deleteMessage: (messageId: string) => void 107 + deleteMessage: (messageId: string) => Promise<void> 108 108 sendMessage: ( 109 109 message: ChatBskyConvoSendMessage.InputSchema['message'], 110 - ) => void 111 - fetchMessageHistory: () => void 110 + ) => Promise<void> 111 + fetchMessageHistory: () => Promise<void> 112 112 } 113 113 | { 114 114 status: ConvoStatus.Backgrounded ··· 116 116 convo: ChatBskyConvoDefs.ConvoView 117 117 error: undefined 118 118 isFetchingHistory: boolean 119 - deleteMessage: (messageId: string) => void 119 + deleteMessage: (messageId: string) => Promise<void> 120 120 sendMessage: ( 121 121 message: ChatBskyConvoSendMessage.InputSchema['message'], 122 - ) => void 123 - fetchMessageHistory: () => void 122 + ) => Promise<void> 123 + fetchMessageHistory: () => Promise<void> 124 124 } 125 125 | { 126 126 status: ConvoStatus.Resuming ··· 128 128 convo: ChatBskyConvoDefs.ConvoView 129 129 error: undefined 130 130 isFetchingHistory: boolean 131 - deleteMessage: (messageId: string) => void 131 + deleteMessage: (messageId: string) => Promise<void> 132 132 sendMessage: ( 133 133 message: ChatBskyConvoSendMessage.InputSchema['message'], 134 - ) => void 135 - fetchMessageHistory: () => void 134 + ) => Promise<void> 135 + fetchMessageHistory: () => Promise<void> 136 136 } 137 137 | { 138 138 status: ConvoStatus.Error ··· 776 776 } 777 777 return true 778 778 }) 779 - .map((item, i) => { 779 + .map((item, i, arr) => { 780 780 let nextMessage = null 781 781 const isMessage = isConvoItemMessage(item) 782 782 ··· 786 786 (ChatBskyConvoDefs.isMessageView(item.message) || 787 787 ChatBskyConvoDefs.isDeletedMessageView(item.message)) 788 788 ) { 789 - const next = items[i + 1] 789 + const next = arr[i + 1] 790 790 791 791 if ( 792 792 isConvoItemMessage(next) &&