Page MenuHomePhabricator

D12805.diff
No OneTemporary

D12805.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
@@ -214,11 +214,41 @@
await updateDeviceList(signedDeviceList);
}
+async function replaceDeviceInDeviceList(
+ identityClient: IdentityServiceClient,
+ userID: string,
+ deviceIDToRemove: string,
+ newDeviceID: string,
+): Promise<void> {
+ const { updateDeviceList } = identityClient;
+ invariant(
+ updateDeviceList,
+ 'updateDeviceList() should be defined on native. ' +
+ 'Are you calling it on a non-primary device?',
+ );
+
+ const { devices } = await fetchLatestDeviceList(identityClient, userID);
+
+ // If the device to remove is not on the list and the new device is already on
+ // the list, return
+ if (!devices.includes(deviceIDToRemove) && devices.includes(newDeviceID)) {
+ return;
+ }
+
+ const newDevices = devices.filter(it => it !== deviceIDToRemove);
+ newDevices.push(newDeviceID);
+
+ const newDeviceList = composeRawDeviceList(newDevices);
+ const signedDeviceList = await signDeviceListUpdate(newDeviceList);
+ await updateDeviceList(signedDeviceList);
+}
+
export {
verifyAndGetDeviceList,
createAndSignSingletonDeviceList,
fetchLatestDeviceList,
addDeviceToDeviceList,
removeDeviceFromDeviceList,
+ replaceDeviceInDeviceList,
signDeviceListUpdate,
};

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 6:08 PM (20 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2576940
Default Alt Text
D12805.diff (1 KB)

Event Timeline