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,15 +18,19 @@ 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 { processDMOpsActionType, queueDMOpsActionType, + sendDMActionTypes, + type SendDMOpsSuccessPayload, } 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'; @@ -198,12 +202,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 && + !dmOpSpecs[dmOperationSpecification.op.type].supportsAutoRetry && + dmOperationSpecification.op.messageID + ) { + 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], ); }