Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3529403
D12741.id42621.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D12741.id42621.diff
View Options
diff --git a/lib/shared/dm-ops/process-dm-ops.js b/lib/shared/dm-ops/process-dm-ops.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/dm-ops/process-dm-ops.js
@@ -0,0 +1,34 @@
+// @flow
+
+import * as React from 'react';
+
+import { dmOpSpecs } from './dm-op-specs.js';
+import { useLoggedInUserInfo } from '../../hooks/account-hooks.js';
+import { useGetLatestMessageEdit } from '../../hooks/latest-message-edit.js';
+import type { DMOperation } from '../../types/dm-ops.js';
+
+function useProcessDMOperation(): (dmOp: DMOperation) => Promise<void> {
+ const fetchMessage = useGetLatestMessageEdit();
+ const utilities = React.useMemo(
+ () => ({
+ fetchMessage,
+ }),
+ [fetchMessage],
+ );
+
+ const loggedInUserInfo = useLoggedInUserInfo();
+ const viewerID = loggedInUserInfo?.id;
+ return React.useCallback(
+ async (dmOp: DMOperation) => {
+ if (!viewerID) {
+ console.log('ignored DMOperation because logged out');
+ return;
+ }
+ await dmOpSpecs[dmOp.type].processDMOperation(dmOp, viewerID, utilities);
+ // TODO: dispatch Redux action
+ },
+ [viewerID, utilities],
+ );
+}
+
+export { useProcessDMOperation };
diff --git a/lib/tunnelbroker/use-peer-to-peer-message-handler.js b/lib/tunnelbroker/use-peer-to-peer-message-handler.js
--- a/lib/tunnelbroker/use-peer-to-peer-message-handler.js
+++ b/lib/tunnelbroker/use-peer-to-peer-message-handler.js
@@ -17,6 +17,7 @@
verifyAndGetDeviceList,
removeDeviceFromDeviceList,
} from '../shared/device-list-utils.js';
+import { useProcessDMOperation } from '../shared/dm-ops/process-dm-ops.js';
import { IdentityClientContext } from '../shared/identity-client-context.js';
import type { DeviceOlmInboundKeys } from '../types/identity-service-types.js';
import {
@@ -53,6 +54,8 @@
const dispatchActionPromise = useDispatchActionPromise();
const primaryDeviceRequestedLogOut = useLogOut(primaryRequestLogoutOptions);
+ const processDMOperation = useProcessDMOperation();
+
return React.useCallback(
async (decryptedMessageContent: string, senderInfo: SenderInfo) => {
const parsedMessageToDevice = JSON.parse(decryptedMessageContent);
@@ -84,6 +87,10 @@
await broadcastDeviceListUpdates(
allPeerDevices.filter(deviceID => deviceID !== deviceIDToLogOut),
);
+ } else if (
+ userActionMessage.type === userActionsP2PMessageTypes.DM_OPERATION
+ ) {
+ await processDMOperation(userActionMessage.op);
} else {
console.warn(
'Unsupported P2P user action message:',
@@ -97,6 +104,7 @@
dispatchActionPromise,
identityClient,
primaryDeviceRequestedLogOut,
+ processDMOperation,
],
);
}
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
@@ -1,6 +1,6 @@
// @flow
-import type { TInterface } from 'tcomb';
+import type { TInterface, TUnion } from 'tcomb';
import t from 'tcomb';
import type { RawMessageInfo } from './message-types.js';
@@ -89,6 +89,11 @@
| DMCreateThreadOperation
| DMCreateSidebarOperation
| DMSendTextMessageOperation;
+export const dmOperationValidator: TUnion<DMOperation> = t.union([
+ dmCreateThreadOperationValidator,
+ dmCreateSidebarOperationValidator,
+ dmSendTextMessageOperationValidator,
+]);
export type DMOperationResult = {
rawMessageInfos: Array<RawMessageInfo>,
diff --git a/lib/types/tunnelbroker/user-actions-peer-to-peer-message-types.js b/lib/types/tunnelbroker/user-actions-peer-to-peer-message-types.js
--- a/lib/types/tunnelbroker/user-actions-peer-to-peer-message-types.js
+++ b/lib/types/tunnelbroker/user-actions-peer-to-peer-message-types.js
@@ -3,10 +3,12 @@
import t, { type TInterface, type TUnion } from 'tcomb';
import { tShape, tString } from '../../utils/validation-utils.js';
+import { type DMOperation, dmOperationValidator } from '../dm-ops.js';
export const userActionsP2PMessageTypes = Object.freeze({
LOG_OUT_PRIMARY_DEVICE: 'LOG_OUT_PRIMARY_DEVICE',
LOG_OUT_SECONDARY_DEVICE: 'LOG_OUT_SECONDARY_DEVICE',
+ DM_OPERATION: 'DM_OPERATION',
});
export type PrimaryDeviceLogoutP2PMessage = {
@@ -26,12 +28,24 @@
type: tString(userActionsP2PMessageTypes.LOG_OUT_SECONDARY_DEVICE),
});
+export type DMOperationP2PMessage = {
+ +type: 'DM_OPERATION',
+ +op: DMOperation,
+};
+export const dmOperationP2PMessageValidator: TInterface<DMOperationP2PMessage> =
+ tShape<DMOperationP2PMessage>({
+ type: tString(userActionsP2PMessageTypes.DM_OPERATION),
+ op: dmOperationValidator,
+ });
+
export type UserActionP2PMessage =
| PrimaryDeviceLogoutP2PMessage
- | SecondaryDeviceLogoutP2PMessage;
+ | SecondaryDeviceLogoutP2PMessage
+ | DMOperationP2PMessage;
export const userActionP2PMessageValidator: TUnion<UserActionP2PMessage> =
t.union([
primaryDeviceLogoutP2PMessageValidator,
secondaryDeviceLogoutP2PMessageValidator,
+ dmOperationP2PMessageValidator,
]);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 25, 6:25 PM (11 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2700020
Default Alt Text
D12741.id42621.diff (4 KB)
Attached To
Mode
D12741: [lib] Process DMOperations when received from peers via Tunnelbroker
Attached
Detach File
Event Timeline
Log In to Comment