Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3356317
D12805.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D12805.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D12805: [lib] introduce new device list function to replace keyserver device
Attached
Detach File
Event Timeline
Log In to Comment