Page MenuHomePhabricator

D13972.id.diff
No OneTemporary

D13972.id.diff

diff --git a/lib/shared/device-list-utils.js b/lib/shared/device-list-utils.js
--- a/lib/shared/device-list-utils.js
+++ b/lib/shared/device-list-utils.js
@@ -8,10 +8,7 @@
useBroadcastDeviceListUpdates,
useGetAndUpdateDeviceListsForUsers,
} from '../hooks/peer-list-hooks.js';
-import {
- getAllPeerDevices,
- getForeignPeerDeviceIDs,
-} from '../selectors/user-selectors.js';
+import { getForeignPeerDeviceIDs } from '../selectors/user-selectors.js';
import type {
IdentityServiceClient,
RawDeviceList,
@@ -206,7 +203,7 @@
identityClient: IdentityServiceClient,
userID: string,
deviceIDToRemove: string,
-): Promise<void> {
+): Promise<?SignedDeviceList> {
const { updateDeviceList } = identityClient;
invariant(
updateDeviceList,
@@ -218,12 +215,13 @@
const newDevices = devices.filter(it => it !== deviceIDToRemove);
if (devices.length === newDevices.length) {
// the device wasn't on the device list
- return;
+ return null;
}
const newDeviceList = composeRawDeviceList(newDevices);
const signedDeviceList = await signDeviceListUpdate(newDeviceList);
await updateDeviceList(signedDeviceList);
+ return signedDeviceList;
}
async function replaceDeviceInDeviceList(
@@ -276,7 +274,6 @@
invariant(identityContext, 'identity context not set');
const { identityClient, getAuthMetadata } = identityContext;
- const allPeerDevices = useSelector(getAllPeerDevices);
const foreignPeerDevices = useSelector(getForeignPeerDeviceIDs);
const broadcastDeviceListUpdates = useBroadcastDeviceListUpdates();
const getAndUpdateDeviceListsForUsers = useGetAndUpdateDeviceListsForUsers();
@@ -315,55 +312,39 @@
return React.useCallback(
async (update: DeviceListUpdate) => {
+ const { userID, deviceID: primaryDeviceID } = await getAuthMetadata();
+ if (!userID || !primaryDeviceID) {
+ throw new Error('missing auth metadata');
+ }
+
+ let signedDeviceList: ?SignedDeviceList;
if (update.type === 'add') {
const { deviceID } = update;
- const { userID, deviceID: primaryDeviceID } = await getAuthMetadata();
- if (!userID || !primaryDeviceID) {
- throw new Error('missing auth metadata');
- }
-
- const signedDeviceList = await addDeviceToDeviceList(
+ signedDeviceList = await addDeviceToDeviceList(
identityClient,
userID,
deviceID,
);
- await sendDeviceListUpdates(signedDeviceList, userID, primaryDeviceID);
} else if (update.type === 'replace') {
const { deviceIDToRemove, newDeviceID } = update;
- const { userID, deviceID: primaryDeviceID } = await getAuthMetadata();
-
- if (!userID || !primaryDeviceID) {
- throw new Error('missing auth metadata');
- }
-
- const signedDeviceList = await replaceDeviceInDeviceList(
+ signedDeviceList = await replaceDeviceInDeviceList(
identityClient,
userID,
deviceIDToRemove,
newDeviceID,
);
- await sendDeviceListUpdates(signedDeviceList, userID, primaryDeviceID);
} else if (update.type === 'remove') {
const { deviceID } = update;
- const { userID } = await getAuthMetadata();
-
- if (!userID) {
- throw new Error('missing auth metadata');
- }
-
- await removeDeviceFromDeviceList(identityClient, userID, deviceID);
- await broadcastDeviceListUpdates(
- allPeerDevices.filter(it => it !== deviceID),
+ signedDeviceList = await removeDeviceFromDeviceList(
+ identityClient,
+ userID,
+ deviceID,
);
}
+
+ await sendDeviceListUpdates(signedDeviceList, userID, primaryDeviceID);
},
- [
- allPeerDevices,
- broadcastDeviceListUpdates,
- getAuthMetadata,
- identityClient,
- sendDeviceListUpdates,
- ],
+ [getAuthMetadata, identityClient, sendDeviceListUpdates],
);
}

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 12:24 AM (12 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2692956
Default Alt Text
D13972.id.diff (3 KB)

Event Timeline