diff --git a/native/chat/chat-input-bar.react.js b/native/chat/chat-input-bar.react.js --- a/native/chat/chat-input-bar.react.js +++ b/native/chat/chat-input-bar.react.js @@ -32,6 +32,7 @@ import { threadInfoSelector } from 'lib/selectors/thread-selectors.js'; import { userStoreSearchIndex } from 'lib/selectors/user-selectors.js'; import { colorIsDark } from 'lib/shared/color-utils.js'; +import { useEditMessage } from 'lib/shared/edit-messages-utils.js'; import { getTypeaheadUserSuggestions, getTypeaheadRegexMatches, @@ -57,7 +58,10 @@ import type { LoadingStatus } from 'lib/types/loading-types.js'; import type { PhotoPaste } from 'lib/types/media-types.js'; import { messageTypes } from 'lib/types/message-types.js'; -import type { MessageInfo } from 'lib/types/message-types.js'; +import type { + SendEditMessageResponse, + MessageInfo, +} from 'lib/types/message-types.js'; import type { Dispatch } from 'lib/types/redux-types.js'; import { type ThreadInfo, @@ -154,6 +158,10 @@ +parentThreadInfo: ?ThreadInfo, +editedMessagePreview: ?MessagePreviewResult, +editedMessageInfo: ?MessageInfo, + +editMessage: ( + messageID: string, + text: string, + ) => Promise, }; type State = { +text: string, @@ -753,6 +761,13 @@ if (!trimMessage(this.state.text)) { return; } + + const editedMessage = this.getEditedMessage(); + if (editedMessage && editedMessage.id) { + this.editMessage(editedMessage.id, this.state.text); + return; + } + this.updateSendButton(''); const { clearableTextInput } = this; @@ -800,6 +815,32 @@ return text !== originalText; }; + editMessage = async (messageID: string, text: string) => { + if (!this.isMessageEdited()) { + this.exitEditMode(); + return; + } + text = trimMessage(text); + try { + await this.props.editMessage(messageID, text); + this.exitEditMode(); + } catch (error) { + Alert.alert( + 'Couldn’t edit the message', + 'Please try again later', + [{ text: 'OK' }], + { + cancelable: true, + }, + ); + } + }; + + getEditedMessage = () => { + const editState = this.props.inputState?.editState; + return editState?.editedMessage; + }; + onPressExitEditMode = () => { if (!this.isMessageEdited()) { this.exitEditMode(); @@ -1066,6 +1107,7 @@ props.threadInfo, getDefaultTextMessageRules().simpleMarkdownRules, ); + const editMessage = useEditMessage(); return ( ); }