Page MenuHomePhabricator

D12805.id42550.diff
No OneTemporary

D12805.id42550.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
@@ -218,11 +218,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 or 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
Sat, Nov 9, 7:20 AM (20 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2450054
Default Alt Text
D12805.id42550.diff (1 KB)

Event Timeline