diff --git a/lib/reducers/dm-operations-queue-reducer.js b/lib/reducers/dm-operations-queue-reducer.js new file mode 100644 --- /dev/null +++ b/lib/reducers/dm-operations-queue-reducer.js @@ -0,0 +1,26 @@ +// @flow + +import { + type QueuedDMOperations, + queueDMOpsActionType, +} from '../types/dm-ops.js'; +import type { BaseAction } from '../types/redux-types.js'; + +function reduceDMOperationsQueue( + store: QueuedDMOperations, + action: BaseAction, +): QueuedDMOperations { + if (action.type === queueDMOpsActionType) { + const { threadID, operation } = action.payload; + return { + ...store, + operations: { + ...store.operations, + [threadID]: [...(store.operations[threadID] ?? []), operation], + }, + }; + } + return store; +} + +export { reduceDMOperationsQueue }; diff --git a/lib/reducers/master-reducer.js b/lib/reducers/master-reducer.js --- a/lib/reducers/master-reducer.js +++ b/lib/reducers/master-reducer.js @@ -7,6 +7,7 @@ import reduceCustomerServer from './custom-server-reducer.js'; import reduceDataLoaded from './data-loaded-reducer.js'; import { reduceDBOpsStore } from './db-ops-reducer.js'; +import { reduceDMOperationsQueue } from './dm-operations-queue-reducer.js'; import { reduceDraftStore } from './draft-reducer.js'; import reduceEnabledApps from './enabled-apps-reducer.js'; import { reduceEntryInfos } from './entry-reducer.js'; @@ -226,6 +227,10 @@ state.tunnelbrokerDeviceToken, action, ), + queuedDMOperations: reduceDMOperationsQueue( + state.queuedDMOperations, + action, + ), }, storeOperations: { draftStoreOperations, 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 @@ -8,6 +8,7 @@ import { type DMOperation, processDMOpsActionType, + queueDMOpsActionType, } from '../../types/dm-ops.js'; import { useDispatch, useSelector } from '../../utils/redux-utils.js'; @@ -38,7 +39,15 @@ utilities, ); if (!processingCheckResult.isProcessingPossible) { - // TODO queue for later + if (processingCheckResult.reason === 'missing_thread') { + dispatch({ + type: queueDMOpsActionType, + payload: { + operation: dmOp, + threadID: processingCheckResult.reason.threadID, + }, + }); + } return; } const { rawMessageInfos, updateInfos } = await dmOpSpecs[ diff --git a/lib/types/dm-ops.js b/lib/types/dm-ops.js --- a/lib/types/dm-ops.js +++ b/lib/types/dm-ops.js @@ -297,6 +297,12 @@ +updateInfos: $ReadOnlyArray, }; +export const queueDMOpsActionType = 'QUEUE_DM_OPS'; +export type QueueDMOpsPayload = { + +operation: DMOperation, + +threadID: string, +}; + export const scheduleP2PMessagesActionType = 'SCHEDULE_P2P_MESSAGES'; export type ScheduleP2PMessagesPayload = { +dmOpID: string, diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -44,6 +44,7 @@ ScheduleP2PMessagesPayload, ProcessDMOpsPayload, QueuedDMOperations, + QueueDMOpsPayload, } from './dm-ops.js'; import type { DraftStore } from './draft-types.js'; import type { EnabledApps, SupportedApps } from './enabled-apps.js'; @@ -1572,7 +1573,8 @@ +type: 'PROCESS_DM_OPS', +payload: ProcessDMOpsPayload, } - | { +type: 'SCHEDULE_P2P_MESSAGES', +payload: ScheduleP2PMessagesPayload }, + | { +type: 'SCHEDULE_P2P_MESSAGES', +payload: ScheduleP2PMessagesPayload } + | { +type: 'QUEUE_DM_OPS', +payload: QueueDMOpsPayload }, }>; export type ActionPayload = ?(Object | Array<*> | $ReadOnlyArray<*> | string);