Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3339840
D12997.id43178.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D12997.id43178.diff
View Options
diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js
--- a/lib/actions/user-actions.js
+++ b/lib/actions/user-actions.js
@@ -3,7 +3,6 @@
import invariant from 'invariant';
import * as React from 'react';
-import { usePeerOlmSessionsCreatorContext } from '../components/peer-olm-session-creator-provider.react.js';
import {
useBroadcastDeviceListUpdates,
useBroadcastAccountDeletion,
@@ -32,7 +31,7 @@
permissionsAndAuthRelatedRequestTimeout,
callIdentityServiceTimeout,
} from '../shared/timeouts.js';
-import { useTunnelbroker } from '../tunnelbroker/tunnelbroker-context.js';
+import { usePeerToPeerCommunication } from '../tunnelbroker/peer-to-peer-context.js';
import type {
LegacyLogInInfo,
LegacyLogInResult,
@@ -74,10 +73,6 @@
SubscriptionUpdateResult,
} from '../types/subscription-types.js';
import type { RawThreadInfos } from '../types/thread-types.js';
-import {
- peerToPeerMessageTypes,
- type EncryptedMessage,
-} from '../types/tunnelbroker/peer-to-peer-message-types.js';
import {
userActionsP2PMessageTypes,
type PrimaryDeviceLogoutP2PMessage,
@@ -268,12 +263,11 @@
throw new Error('Identity service client is not initialized');
}
- const { sendMessageToDevice } = useTunnelbroker();
const broadcastDeviceListUpdates = useBroadcastDeviceListUpdates();
+ const { broadcastEphemeralMessage } = usePeerToPeerCommunication();
const foreignPeerDevices = useSelector(getForeignPeerDevices);
const logOut = useLogOut(primaryDeviceLogOutOptions);
- const { createOlmSessionsWithPeer } = usePeerOlmSessionsCreatorContext();
return React.useCallback(async () => {
const { identityClient, getAuthMetadata } = identityContext;
const authMetadata = await getAuthMetadata();
@@ -288,51 +282,15 @@
throw new Error('Used primary device logout on a non-primary device');
}
- // create and send Olm Tunnelbroker messages to secondaryDevices
- const { olmAPI } = getConfig();
- await olmAPI.initializeCryptoAccount();
const messageContents: PrimaryDeviceLogoutP2PMessage = {
type: userActionsP2PMessageTypes.LOG_OUT_PRIMARY_DEVICE,
};
- for (const deviceID of secondaryDevices) {
- try {
- const encryptedData = await olmAPI.encrypt(
- JSON.stringify(messageContents),
- deviceID,
- );
- const encryptedMessage: EncryptedMessage = {
- type: peerToPeerMessageTypes.ENCRYPTED_MESSAGE,
- senderInfo: { deviceID: thisDeviceID, userID },
- encryptedData,
- };
- await sendMessageToDevice({
- deviceID,
- payload: JSON.stringify(encryptedMessage),
- });
- } catch {
- try {
- await createOlmSessionsWithPeer(userID, deviceID);
- const encryptedData = await olmAPI.encrypt(
- JSON.stringify(messageContents),
- deviceID,
- );
- const encryptedMessage: EncryptedMessage = {
- type: peerToPeerMessageTypes.ENCRYPTED_MESSAGE,
- senderInfo: { deviceID: thisDeviceID, userID },
- encryptedData,
- };
- await sendMessageToDevice({
- deviceID,
- payload: JSON.stringify(encryptedMessage),
- });
- } catch (err) {
- console.warn(
- `Error sending primary device logout message to device ${deviceID}:`,
- err,
- );
- }
- }
- }
+ const recipients = secondaryDevices.map(deviceID => ({ userID, deviceID }));
+ await broadcastEphemeralMessage(
+ JSON.stringify(messageContents),
+ recipients,
+ authMetadata,
+ );
// - logOut() performs device list update by calling Identity RPC
// - broadcastDeviceListUpdates asks peers to download it from identity
@@ -344,12 +302,11 @@
await broadcastDeviceListUpdates(foreignPeerDevices);
return logOutResult;
}, [
- createOlmSessionsWithPeer,
broadcastDeviceListUpdates,
+ broadcastEphemeralMessage,
foreignPeerDevices,
identityContext,
logOut,
- sendMessageToDevice,
]);
}
@@ -358,14 +315,13 @@
});
function useSecondaryDeviceLogOut(): () => Promise<LogOutResult> {
- const { sendMessageToDevice } = useTunnelbroker();
const logOut = useLogOut(secondaryDeviceLogOutOptions);
const identityContext = React.useContext(IdentityClientContext);
if (!identityContext) {
throw new Error('Identity service client is not initialized');
}
- const { createOlmSessionsWithPeer } = usePeerOlmSessionsCreatorContext();
+ const { broadcastEphemeralMessage } = usePeerToPeerCommunication();
return React.useCallback(async () => {
const { identityClient, getAuthMetadata } = identityContext;
@@ -388,44 +344,16 @@
const messageContents: SecondaryDeviceLogoutP2PMessage = {
type: userActionsP2PMessageTypes.LOG_OUT_SECONDARY_DEVICE,
};
- try {
- const encryptedData = await olmAPI.encrypt(
- JSON.stringify(messageContents),
- primaryDeviceID,
- );
- const encryptedMessage: EncryptedMessage = {
- type: peerToPeerMessageTypes.ENCRYPTED_MESSAGE,
- senderInfo: { deviceID, userID },
- encryptedData,
- };
- await sendMessageToDevice({
- deviceID: primaryDeviceID,
- payload: JSON.stringify(encryptedMessage),
- });
- } catch {
- try {
- await createOlmSessionsWithPeer(userID, primaryDeviceID);
- const encryptedData = await olmAPI.encrypt(
- JSON.stringify(messageContents),
- primaryDeviceID,
- );
- const encryptedMessage: EncryptedMessage = {
- type: peerToPeerMessageTypes.ENCRYPTED_MESSAGE,
- senderInfo: { deviceID, userID },
- encryptedData,
- };
- await sendMessageToDevice({
- deviceID: primaryDeviceID,
- payload: JSON.stringify(encryptedMessage),
- });
- } catch (err) {
- console.warn('Error sending secondary device logout message:', err);
- }
- }
+ const recipient = { userID, deviceID: primaryDeviceID };
+ await broadcastEphemeralMessage(
+ JSON.stringify(messageContents),
+ [recipient],
+ authMetadata,
+ );
// log out of identity service, keyserver and visually
return logOut();
- }, [createOlmSessionsWithPeer, identityContext, sendMessageToDevice, logOut]);
+ }, [identityContext, broadcastEphemeralMessage, logOut]);
}
const claimUsernameActionTypes = Object.freeze({
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 8:41 PM (16 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2559265
Default Alt Text
D12997.id43178.diff (6 KB)
Attached To
Mode
D12997: [lib] Use the useBroadcastOlmMessage hook in logout actions
Attached
Detach File
Event Timeline
Log In to Comment