Skip to content

Commit

Permalink
[lib] add option to mark DMOperationSpecification as sendOnly
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xsanm committed Aug 28, 2024
1 parent 0979775 commit 062159e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/shared/dm-ops/dm-op-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type OutboundDMOperationSpecification = {
+recipients:
| { +type: 'all_peer_devices' | 'self_devices' }
| { +type: 'some_users', +userIDs: $ReadOnlyArray<string> },
+sendOnly?: boolean,
};

// The operation received from other peers, causes changes to
Expand Down
47 changes: 37 additions & 10 deletions lib/shared/dm-ops/process-dm-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ function useProcessDMOperation(): (
return;
}

const { op: dmOp } = dmOperationSpecification;

let outboundP2PMessages: ?$ReadOnlyArray<OutboundP2PMessage> = null;
if (
dmOperationSpecification.type === dmOperationSpecificationTypes.OUTBOUND
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 062159e

Please sign in to comment.