Convert /verify to checkDeviceTrust

Also de-promiseify the code a bit
pull/21833/head
David Baker 2020-01-03 12:08:35 +00:00
parent 560cff0ae1
commit c2723176e4
1 changed files with 42 additions and 44 deletions

View File

@ -780,15 +780,14 @@ export const CommandMap = {
const deviceId = matches[2];
const fingerprint = matches[3];
return success(
// Promise.resolve to handle transition from static result to promise; can be removed
// in future
Promise.resolve(cli.getStoredDevice(userId, deviceId)).then((device) => {
return success((async () => {
const device = await cli.getStoredDevice(userId, deviceId);
if (!device) {
throw new Error(_t('Unknown (user, device) pair:') + ` (${userId}, ${deviceId})`);
}
const deviceTrust = await cli.checkDeviceTrust(userId, deviceId);
if (device.isVerified()) {
if (deviceTrust.isVerified()) {
if (device.getFingerprint() === fingerprint) {
throw new Error(_t('Device already verified!'));
} else {
@ -810,8 +809,8 @@ export const CommandMap = {
}));
}
return cli.setDeviceVerified(userId, deviceId, true);
}).then(() => {
await cli.setDeviceVerified(userId, deviceId, true);
// Tell the user we verified everything
const InfoDialog = sdk.getComponent('dialogs.InfoDialog');
Modal.createTrackedDialog('Slash Commands', 'Verified key', InfoDialog, {
@ -826,8 +825,7 @@ export const CommandMap = {
</p>
</div>,
});
}),
);
})());
}
}
return reject(this.getUsage());