Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3182027
D12805.id42550.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.id42550.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
@@ -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
Details
Attached
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)
Attached To
Mode
D12805: [lib] introduce new device list function to replace keyserver device
Attached
Detach File
Event Timeline
Log In to Comment