diff --git a/lib/shared/dm-ops/process-dm-ops.js b/lib/shared/dm-ops/process-dm-ops.js --- a/lib/shared/dm-ops/process-dm-ops.js +++ b/lib/shared/dm-ops/process-dm-ops.js @@ -18,16 +18,20 @@ import { useDispatchWithMetadata } from '../../hooks/ops-hooks.js'; import { mergeUpdatesWithMessageInfos } from '../../reducers/message-reducer.js'; import { getAllPeerUserIDAndDeviceIDs } from '../../selectors/user-selectors.js'; +import { usePeerToPeerCommunication } from '../../tunnelbroker/peer-to-peer-context.js'; import { dmOperationTypes, processDMOpsActionType, queueDMOpsActionType, + sendDMActionTypes, + type SendDMOpsPayload, } from '../../types/dm-ops.js'; import type { RawThreadInfo } from '../../types/minimally-encoded-thread-permissions-types.js'; import type { OutboundP2PMessage } from '../../types/sqlite-types.js'; import { threadTypes } from '../../types/thread-types-enum.js'; import type { LegacyRawThreadInfo } from '../../types/thread-types.js'; import { updateTypes } from '../../types/update-types-enum.js'; +import { useDispatchActionPromise } from '../../utils/redux-promise-utils.js'; import { useSelector } from '../../utils/redux-utils.js'; import { messageSpecs } from '../messages/message-specs.js'; import { updateSpecs } from '../updates/update-specs.js'; @@ -200,12 +204,41 @@ dmOperationSpecification: OutboundDMOperationSpecification, ) => Promise { const processDMOps = useProcessDMOperation(); + const dispatchActionPromise = useDispatchActionPromise(); + const { getDMOpsSendingPromise } = usePeerToPeerCommunication(); return React.useCallback( async (dmOperationSpecification: OutboundDMOperationSpecification) => { + const { promise } = getDMOpsSendingPromise(); await processDMOps(dmOperationSpecification); + + if ( + dmOperationSpecification.type === + dmOperationSpecificationTypes.OUTBOUND && + !dmOperationSpecification.supportsAutoRetry && + dmOperationSpecification.op.type === dmOperationTypes.SEND_TEXT_MESSAGE + ) { + const messageID: string = dmOperationSpecification.op.messageID; + + const sendingPromise: Promise = (async () => { + const outboundP2PMessageIDs = await promise; + return { + messageID, + outboundP2PMessageIDs, + }; + })(); + + void dispatchActionPromise( + sendDMActionTypes, + sendingPromise, + undefined, + { + messageID, + }, + ); + } }, - [processDMOps], + [dispatchActionPromise, getDMOpsSendingPromise, processDMOps], ); }