Page MenuHomePhabricator

D12996.id43177.diff
No OneTemporary

D12996.id43177.diff

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
@@ -501,7 +501,7 @@
});
const accountDeletionBroadcastOptions = Object.freeze({
- broadcastToOwnDevices: true,
+ includeOwnDevices: true,
});
function useDeleteAccount(): (password: ?string) => Promise<LogOutResult> {
const client = React.useContext(IdentityClientContext);
diff --git a/lib/hooks/peer-list-hooks.js b/lib/hooks/peer-list-hooks.js
--- a/lib/hooks/peer-list-hooks.js
+++ b/lib/hooks/peer-list-hooks.js
@@ -4,12 +4,12 @@
import * as React from 'react';
import { setPeerDeviceListsActionType } from '../actions/aux-user-actions.js';
-import { usePeerOlmSessionsCreatorContext } from '../components/peer-olm-session-creator-provider.react.js';
import {
getAllPeerDevices,
- getForeignPeerDevices,
+ getAllPeerUserIDAndDeviceIDs,
} from '../selectors/user-selectors.js';
import { IdentityClientContext } from '../shared/identity-client-context.js';
+import { usePeerToPeerCommunication } from '../tunnelbroker/peer-to-peer-context.js';
import { useTunnelbroker } from '../tunnelbroker/tunnelbroker-context.js';
import type {
UsersRawDeviceLists,
@@ -19,7 +19,6 @@
} from '../types/identity-service-types.js';
import {
type DeviceListUpdated,
- type EncryptedMessage,
peerToPeerMessageTypes,
} from '../types/tunnelbroker/peer-to-peer-message-types.js';
import {
@@ -143,28 +142,24 @@
);
}
-function useBroadcastAccountDeletion(
- options: { broadcastToOwnDevices?: boolean } = {},
-): () => Promise<void> {
- const { broadcastToOwnDevices } = options;
+function useBroadcastAccountDeletion(options: {
+ +includeOwnDevices: boolean,
+}): () => Promise<void> {
+ const { includeOwnDevices } = options;
const identityContext = React.useContext(IdentityClientContext);
if (!identityContext) {
throw new Error('Identity service client is not initialized');
}
- const { sendMessageToDevice } = useTunnelbroker();
+ const { getAuthMetadata } = identityContext;
- const devicesSelector = broadcastToOwnDevices
- ? getAllPeerDevices
- : getForeignPeerDevices;
- const peerDevices = useSelector(devicesSelector);
- const { createOlmSessionsWithPeer } = usePeerOlmSessionsCreatorContext();
+ const peers = useSelector(getAllPeerUserIDAndDeviceIDs);
+ const { broadcastEphemeralMessage } = usePeerToPeerCommunication();
return React.useCallback(async () => {
- const { getAuthMetadata } = identityContext;
const authMetadata = await getAuthMetadata();
- const { userID, deviceID: thisDeviceID } = authMetadata;
- if (!thisDeviceID || !userID) {
+ const { userID: thisUserID, deviceID: thisDeviceID } = authMetadata;
+ if (!thisDeviceID || !thisUserID) {
throw new Error('No auth metadata');
}
// create and send Olm Tunnelbroker messages to peers
@@ -176,48 +171,13 @@
};
const rawPayload = JSON.stringify(deletionMessage);
- const recipientDeviceIDs = peerDevices.filter(
- peerDeviceID => peerDeviceID !== thisDeviceID,
+ const recipients = peers.filter(
+ peer =>
+ peer.deviceID !== thisDeviceID &&
+ (includeOwnDevices || peer.userID !== thisUserID),
);
- for (const deviceID of recipientDeviceIDs) {
- try {
- const encryptedData = await olmAPI.encrypt(rawPayload, 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(rawPayload, 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 account deletion message to device ${deviceID}:`,
- err,
- );
- }
- }
- }
- }, [
- createOlmSessionsWithPeer,
- identityContext,
- peerDevices,
- sendMessageToDevice,
- ]);
+ await broadcastEphemeralMessage(rawPayload, recipients, authMetadata);
+ }, [broadcastEphemeralMessage, getAuthMetadata, includeOwnDevices, peers]);
}
export {
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
@@ -48,7 +48,7 @@
// When re-broadcasting, we want to do it only to foreign peers
// to avoid a vicious circle of deletion messages sent by own devices.
const accountDeletionBroadcastOptions = Object.freeze({
- broadcastToOwnDevices: false,
+ includeOwnDevices: false,
});
// handles `peerToPeerMessageTypes.ENCRYPTED_MESSAGE`

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 9:30 PM (12 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2559261
Default Alt Text
D12996.id43177.diff (5 KB)

Event Timeline