From 062159e457ced252cae50774f634349cfcc35a10 Mon Sep 17 00:00:00 2001 From: xsanm Date: Tue, 27 Aug 2024 21:19:59 +0200 Subject: [PATCH] [lib] add option to mark `DMOperationSpecification` as `sendOnly` Summary: [ENG-8568](https://linear.app/comm/issue/ENG-8568/logic-for-adding-a-user-user-joining-a-thick-thread) There are ops like `ADD_VIEWER_TO_THREAD_MEMBERS` that are only meant to be sent to other peers, and should never be processed on client which is generating this operation. Depends on D13181 Test Plan: Tested later in the stack Reviewers: tomek, inka Reviewed By: tomek Subscribers: ashoat Differential Revision: https://phab.comm.dev/D13182 --- lib/shared/dm-ops/dm-op-utils.js | 1 + lib/shared/dm-ops/process-dm-ops.js | 47 +++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/lib/shared/dm-ops/dm-op-utils.js b/lib/shared/dm-ops/dm-op-utils.js index d9a18510fc..d1bd539a27 100644 --- a/lib/shared/dm-ops/dm-op-utils.js +++ b/lib/shared/dm-ops/dm-op-utils.js @@ -58,6 +58,7 @@ export type OutboundDMOperationSpecification = { +recipients: | { +type: 'all_peer_devices' | 'self_devices' } | { +type: 'some_users', +userIDs: $ReadOnlyArray }, + +sendOnly?: boolean, }; // The operation received from other peers, causes changes to diff --git a/lib/shared/dm-ops/process-dm-ops.js b/lib/shared/dm-ops/process-dm-ops.js index 161776fed2..bbeb927670 100644 --- a/lib/shared/dm-ops/process-dm-ops.js +++ b/lib/shared/dm-ops/process-dm-ops.js @@ -68,6 +68,8 @@ function useProcessDMOperation(): ( return; } + const { op: dmOp } = dmOperationSpecification; + let outboundP2PMessages: ?$ReadOnlyArray = null; if ( dmOperationSpecification.type === dmOperationSpecificationTypes.OUTBOUND @@ -94,7 +96,41 @@ function useProcessDMOperation(): ( dispatchMetadata = dmOperationSpecification.metadata; } - const { op: dmOp } = dmOperationSpecification; + let messageIDWithoutAutoRetry: ?string = null; + if ( + dmOperationSpecification.type === + dmOperationSpecificationTypes.OUTBOUND && + !dmOpSpecs[dmOp.type].supportsAutoRetry + ) { + messageIDWithoutAutoRetry = dmOp.messageID; + } + + if ( + dmOperationSpecification.type === + dmOperationSpecificationTypes.OUTBOUND && + dmOperationSpecification.sendOnly + ) { + const notificationsCreationData = await dmOpSpecs[ + dmOp.type + ].notificationsCreationData?.(dmOp, utilities); + + dispatchWithMetadata( + { + type: processDMOpsActionType, + payload: { + rawMessageInfos: [], + updateInfos: [], + outboundP2PMessages, + messageIDWithoutAutoRetry, + notificationsCreationData, + }, + }, + dispatchMetadata, + ); + + return; + } + const processingCheckResult = dmOpSpecs[dmOp.type].canBeProcessed( dmOp, viewerID, @@ -194,15 +230,6 @@ function useProcessDMOperation(): ( }); } - let messageIDWithoutAutoRetry: ?string = null; - if ( - dmOperationSpecification.type === - dmOperationSpecificationTypes.OUTBOUND && - !dmOpSpecs[dmOperationSpecification.op.type].supportsAutoRetry - ) { - messageIDWithoutAutoRetry = dmOperationSpecification.op.messageID; - } - dispatchWithMetadata( { type: processDMOpsActionType,