diff --git a/native/input/input-state-container.react.js b/native/input/input-state-container.react.js --- a/native/input/input-state-container.react.js +++ b/native/input/input-state-container.react.js @@ -5,18 +5,13 @@ import * as React from 'react'; import { Platform } from 'react-native'; import { createSelector } from 'reselect'; -import uuid from 'uuid'; -import type { - SendMultimediaMessageInput, - SendTextMessageInput, -} from 'lib/actions/message-actions.js'; +import type { SendMultimediaMessageInput } from 'lib/actions/message-actions.js'; import { createLocalMessageActionType, sendMultimediaMessageActionTypes, sendTextMessageActionTypes, useSendMultimediaMessage, - useSendTextMessage, } from 'lib/actions/message-actions.js'; import { queueReportsActionType } from 'lib/actions/report-actions.js'; import { useNewThinThread } from 'lib/actions/thread-actions.js'; @@ -30,6 +25,7 @@ useBlobServiceUpload, } from 'lib/actions/upload-actions.js'; import commStaffCommunity from 'lib/facts/comm-staff-community.js'; +import { useInputStateContainerSendTextMessage } from 'lib/hooks/input-state-container-hooks.js'; import { useNewThickThread } from 'lib/hooks/thread-hooks.js'; import type { CallSingleKeyserverEndpointOptions, @@ -46,11 +42,6 @@ combineLoadingStatuses, createLoadingStatusSelector, } from 'lib/selectors/loading-selectors.js'; -import { - dmOperationSpecificationTypes, - type OutboundDMOperationSpecification, -} from 'lib/shared/dm-ops/dm-op-utils.js'; -import { useProcessAndSendDMOperation } from 'lib/shared/dm-ops/process-dm-ops.js'; import { createMediaMessageInfo, useMessageCreationSideEffectsFunc, @@ -93,7 +84,6 @@ import { threadTypeIsThick, threadTypeIsSidebar, - thickThreadTypes, } from 'lib/types/thread-types-enum.js'; import { type ClientNewThinThreadRequest, @@ -166,10 +156,12 @@ +sendMultimediaMessage: ( input: SendMultimediaMessageInput, ) => Promise, - +sendTextMessage: (input: SendTextMessageInput) => Promise, - +processAndSendDMOperation: ( - dmOperationSpecification: OutboundDMOperationSpecification, - ) => Promise, + +sendTextMessage: ( + messageInfo: RawTextMessageInfo, + threadInfo: ThreadInfo, + parentThreadInfo: ?ThreadInfo, + sidebarCreation: boolean, + ) => Promise, +newThinThread: ( request: ClientNewThinThreadRequest, ) => Promise, @@ -467,48 +459,6 @@ ); }; - async processAndSendTextMessageDMOperation( - messageInfo: RawTextMessageInfo, - inputThreadInfo: ThreadInfo, - ) { - void this.props.processAndSendDMOperation({ - type: dmOperationSpecificationTypes.OUTBOUND, - op: { - type: 'send_text_message', - threadID: inputThreadInfo.id, - creatorID: messageInfo.creatorID, - time: Date.now(), - messageID: uuid.v4(), - text: messageInfo.text, - }, - recipients: { - type: 'all_thread_members', - threadID: - inputThreadInfo.type === thickThreadTypes.THICK_SIDEBAR && - inputThreadInfo.parentThreadID - ? inputThreadInfo.parentThreadID - : inputThreadInfo.id, - }, - }); - } - - async generateAndSendTextMessageAction( - messageInfo: RawTextMessageInfo, - threadInfo: ThreadInfo, - parentThreadInfo: ?ThreadInfo, - ) { - if (threadTypeIsThick(threadInfo.type)) { - void this.processAndSendTextMessageDMOperation(messageInfo, threadInfo); - return; - } - void this.props.dispatchActionPromise( - sendTextMessageActionTypes, - this.sendTextMessageAction(messageInfo, threadInfo, parentThreadInfo), - undefined, - messageInfo, - ); - } - sendTextMessage = async ( messageInfo: RawTextMessageInfo, inputThreadInfo: ThreadInfo, @@ -526,20 +476,23 @@ } if (!threadIsPending(inputThreadInfo.id)) { - void this.generateAndSendTextMessageAction( + void this.props.dispatchActionPromise( + sendTextMessageActionTypes, + this.sendTextMessageAction( + messageInfo, + inputThreadInfo, + parentThreadInfo, + ), + undefined, messageInfo, - inputThreadInfo, - parentThreadInfo, ); return; } - if (!threadTypeIsThick(inputThreadInfo.type)) { - this.props.dispatch({ - type: sendTextMessageActionTypes.started, - payload: messageInfo, - }); - } + this.props.dispatch({ + type: sendTextMessageActionTypes.started, + payload: messageInfo, + }); let threadInfo = inputThreadInfo; const { viewerID } = this.props; @@ -566,13 +519,11 @@ const copy = cloneError(e); copy.localID = messageInfo.localID; copy.threadID = messageInfo.threadID; - if (!threadTypeIsThick(inputThreadInfo.type)) { - this.props.dispatch({ - type: sendTextMessageActionTypes.failed, - payload: copy, - error: true, - }); - } + this.props.dispatch({ + type: sendTextMessageActionTypes.failed, + payload: copy, + error: true, + }); return; } finally { this.pendingThreadCreations.delete(threadInfo.id); @@ -589,10 +540,15 @@ id: newThreadID, }; - void this.generateAndSendTextMessageAction( + void this.props.dispatchActionPromise( + sendTextMessageActionTypes, + this.sendTextMessageAction( + newMessageInfo, + newThreadInfo, + parentThreadInfo, + ), + undefined, newMessageInfo, - newThreadInfo, - parentThreadInfo, ); }; @@ -635,20 +591,14 @@ ); const sidebarCreation = this.pendingSidebarCreationMessageLocalIDs.has(localID); - const result = await this.props.sendTextMessage({ - threadID: messageInfo.threadID, - localID, - text: messageInfo.text, + const result = await this.props.sendTextMessage( + messageInfo, + threadInfo, + parentThreadInfo, sidebarCreation, - }); + ); this.pendingSidebarCreationMessageLocalIDs.delete(localID); - return { - localID, - serverID: result.id, - threadID: messageInfo.threadID, - time: result.time, - interface: result.interface, - }; + return result; } catch (e) { const copy = cloneError(e); copy.localID = messageInfo.localID; @@ -1809,7 +1759,7 @@ const callUploadMultimedia = useLegacyAshoatKeyserverCall(uploadMultimedia); const callBlobServiceUpload = useBlobServiceUpload(); const callSendMultimediaMessage = useSendMultimediaMessage(); - const callSendTextMessage = useSendTextMessage(); + const callSendTextMessage = useInputStateContainerSendTextMessage(); const callNewThinThread = useNewThinThread(); const callNewThickThread = useNewThickThread(); const dispatchActionPromise = useDispatchActionPromise(); @@ -1818,7 +1768,6 @@ const staffCanSee = useStaffCanSee(); const textMessageCreationSideEffectsFunc = useMessageCreationSideEffectsFunc(messageTypes.TEXT); - const processAndSendDMOperation = useProcessAndSendDMOperation(); return ( Promise, - +sendTextMessage: (input: SendTextMessageInput) => Promise, - +processAndSendDMOperation: ( - dmOperationSpecification: OutboundDMOperationSpecification, - ) => Promise, + +sendTextMessage: ( + messageInfo: RawTextMessageInfo, + threadInfo: ThreadInfo, + parentThreadInfo: ?ThreadInfo, + sidebarCreation: boolean, + ) => Promise, +newThinThread: ( request: ClientNewThinThreadRequest, ) => Promise, @@ -1284,48 +1276,6 @@ ); } - async processAndSendTextMessageDMOperation( - messageInfo: RawTextMessageInfo, - inputThreadInfo: ThreadInfo, - ) { - void this.props.processAndSendDMOperation({ - type: dmOperationSpecificationTypes.OUTBOUND, - op: { - type: 'send_text_message', - threadID: inputThreadInfo.id, - creatorID: messageInfo.creatorID, - time: Date.now(), - messageID: uuid.v4(), - text: messageInfo.text, - }, - recipients: { - type: 'all_thread_members', - threadID: - inputThreadInfo.type === thickThreadTypes.THICK_SIDEBAR && - inputThreadInfo.parentThreadID - ? inputThreadInfo.parentThreadID - : inputThreadInfo.id, - }, - }); - } - - async generateAndSendTextMessageAction( - messageInfo: RawTextMessageInfo, - threadInfo: ThreadInfo, - parentThreadInfo: ?ThreadInfo, - ) { - if (threadTypeIsThick(threadInfo.type)) { - void this.processAndSendTextMessageDMOperation(messageInfo, threadInfo); - return; - } - void this.props.dispatchActionPromise( - sendTextMessageActionTypes, - this.sendTextMessageAction(messageInfo, threadInfo, parentThreadInfo), - undefined, - messageInfo, - ); - } - async sendTextMessage( messageInfo: RawTextMessageInfo, inputThreadInfo: ThreadInfo, @@ -1343,20 +1293,23 @@ } if (!threadIsPending(inputThreadInfo.id)) { - void this.generateAndSendTextMessageAction( + void this.props.dispatchActionPromise( + sendTextMessageActionTypes, + this.sendTextMessageAction( + messageInfo, + inputThreadInfo, + parentThreadInfo, + ), + undefined, messageInfo, - inputThreadInfo, - parentThreadInfo, ); return; } - if (!threadTypeIsThick(inputThreadInfo.type)) { - this.props.dispatch({ - type: sendTextMessageActionTypes.started, - payload: messageInfo, - }); - } + this.props.dispatch({ + type: sendTextMessageActionTypes.started, + payload: messageInfo, + }); let threadInfo = inputThreadInfo; const { viewerID } = this.props; @@ -1383,13 +1336,11 @@ const copy = cloneError(e); copy.localID = messageInfo.localID; copy.threadID = messageInfo.threadID; - if (!threadTypeIsThick(inputThreadInfo.type)) { - this.props.dispatch({ - type: sendTextMessageActionTypes.failed, - payload: copy, - error: true, - }); - } + this.props.dispatch({ + type: sendTextMessageActionTypes.failed, + payload: copy, + error: true, + }); return; } finally { this.pendingThreadCreations.delete(threadInfo.id); @@ -1405,11 +1356,15 @@ ...threadInfo, id: newThreadID, }; - - void this.generateAndSendTextMessageAction( + void this.props.dispatchActionPromise( + sendTextMessageActionTypes, + this.sendTextMessageAction( + newMessageInfo, + newThreadInfo, + parentThreadInfo, + ), + undefined, newMessageInfo, - newThreadInfo, - parentThreadInfo, ); } @@ -1431,20 +1386,14 @@ ); const sidebarCreation = this.pendingSidebarCreationMessageLocalIDs.has(localID); - const result = await this.props.sendTextMessage({ - threadID: messageInfo.threadID, - localID, - text: messageInfo.text, + const result = await this.props.sendTextMessage( + messageInfo, + threadInfo, + parentThreadInfo, sidebarCreation, - }); + ); this.pendingSidebarCreationMessageLocalIDs.delete(localID); - return { - localID, - serverID: result.id, - threadID: messageInfo.threadID, - time: result.time, - interface: result.interface, - }; + return result; } catch (e) { const copy = cloneError(e); copy.localID = messageInfo.localID; @@ -1731,14 +1680,13 @@ const callBlobServiceUpload = useBlobServiceUpload(); const callDeleteUpload = useDeleteUpload(); const callSendMultimediaMessage = useLegacySendMultimediaMessage(); - const callSendTextMessage = useSendTextMessage(); + const callSendTextMessage = useInputStateContainerSendTextMessage(); const callNewThinThread = useNewThinThread(); const callNewThickThread = useNewThickThread(); const dispatch = useDispatch(); const dispatchActionPromise = useDispatchActionPromise(); const modalContext = useModalContext(); const identityContext = React.useContext(IdentityClientContext); - const processAndSendDMOperation = useProcessAndSendDMOperation(); const [sendCallbacks, setSendCallbacks] = React.useState< $ReadOnlyArray<() => mixed>, @@ -1771,7 +1719,6 @@ deleteUpload={callDeleteUpload} sendMultimediaMessage={callSendMultimediaMessage} sendTextMessage={callSendTextMessage} - processAndSendDMOperation={processAndSendDMOperation} newThinThread={callNewThinThread} newThickThread={callNewThickThread} dispatch={dispatch}