You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-11 20:22:36 +03:00
Convert /verify to checkDeviceTrust
Also de-promiseify the code a bit
This commit is contained in:
@@ -780,15 +780,14 @@ export const CommandMap = {
|
|||||||
const deviceId = matches[2];
|
const deviceId = matches[2];
|
||||||
const fingerprint = matches[3];
|
const fingerprint = matches[3];
|
||||||
|
|
||||||
return success(
|
return success((async () => {
|
||||||
// Promise.resolve to handle transition from static result to promise; can be removed
|
const device = await cli.getStoredDevice(userId, deviceId);
|
||||||
// in future
|
|
||||||
Promise.resolve(cli.getStoredDevice(userId, deviceId)).then((device) => {
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
throw new Error(_t('Unknown (user, device) pair:') + ` (${userId}, ${deviceId})`);
|
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) {
|
if (device.getFingerprint() === fingerprint) {
|
||||||
throw new Error(_t('Device already verified!'));
|
throw new Error(_t('Device already verified!'));
|
||||||
} else {
|
} else {
|
||||||
@@ -810,8 +809,8 @@ export const CommandMap = {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return cli.setDeviceVerified(userId, deviceId, true);
|
await cli.setDeviceVerified(userId, deviceId, true);
|
||||||
}).then(() => {
|
|
||||||
// Tell the user we verified everything
|
// Tell the user we verified everything
|
||||||
const InfoDialog = sdk.getComponent('dialogs.InfoDialog');
|
const InfoDialog = sdk.getComponent('dialogs.InfoDialog');
|
||||||
Modal.createTrackedDialog('Slash Commands', 'Verified key', InfoDialog, {
|
Modal.createTrackedDialog('Slash Commands', 'Verified key', InfoDialog, {
|
||||||
@@ -826,8 +825,7 @@ export const CommandMap = {
|
|||||||
</p>
|
</p>
|
||||||
</div>,
|
</div>,
|
||||||
});
|
});
|
||||||
}),
|
})());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return reject(this.getUsage());
|
return reject(this.getUsage());
|
||||||
|
|||||||
Reference in New Issue
Block a user