-
-
Notifications
You must be signed in to change notification settings - Fork 813
Replace uses of checkDeviceTrust with getDeviceVerificationStatus
#10663
Replace uses of checkDeviceTrust with getDeviceVerificationStatus
#10663
Conversation
e16cba5 to
60f6e20
Compare
60f6e20 to
2545dc6
Compare
2545dc6 to
d9c3e33
Compare
d9c3e33 to
e487a07
Compare
e487a07 to
1d88f27
Compare
1d88f27 to
3fc5044
Compare
36f9494 to
b2284c3
Compare
b2284c3 to
f1adf65
Compare
We have a method called `fetchDevicesWithVerification` which is currently used in the new Session manager. Let's use it for the (old) Devices Panel too, because it allows us to check the device verification upfront, rather than on the fly, which is going to be handy when that operation becomes async
these are in an async method, but currently use `some`. We need to invent an `asyncSome` (we already have an `asyncEvery`) and use that
... which means making it async
This is ok except we need an "unmounted" guard because it's an old-style componment
639cc2b to
1cc6e40
Compare
| /** | ||
| * Async version of Array.some. | ||
| */ | ||
| export async function asyncSome<T>(values: T[], predicate: (value: T) => Promise<boolean>): Promise<boolean> { | ||
| for (const value of values) { | ||
| if (await predicate(value)) return true; | ||
| } | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might this be worth doing with Promise.race or similar as one slow or never resolving promise might wedge things up here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe. I'm somewhat keen to keep it symmetrical with asyncEvery, and the semantics are much easier to reason about if the promises happen serially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair, didn't see asyncEvery
| // For other people's devices, the more general verified check that | ||
| // includes locally verified devices can be used. | ||
| const isVerified = isMe ? deviceTrust.isCrossSigningVerified() : deviceTrust.isVerified(); | ||
| const isVerified = deviceTrust && (isMe ? deviceTrust.crossSigningVerified : deviceTrust.isVerified()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const isVerified = deviceTrust && (isMe ? deviceTrust.crossSigningVerified : deviceTrust.isVerified()); | |
| const isVerified = isMe ? deviceTrust?.crossSigningVerified : deviceTrust?.isVerified()); |
To match L177 in the same file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem here is avoiding the implicit cast to boolean if deviceTrust is nullish. We could do something like isVerified = !!(isMe ? deviceTrust?.crossSigningVerified : deviceTrust?.isVerified())) but I'm far from convinced that's clearer.
At L177, we have an explicit check on deviceTrust, so I'd say my variant of this is closer to L177 than yours.
src/DeviceListener.ts
Outdated
| .getCrypto() | ||
| ?.getDeviceVerificationStatus(cli.getUserId()!, device.deviceId!); | ||
| !.getDeviceVerificationStatus(cli.getUserId()!, device.deviceId!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ! needs to be on .getCrypto()!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bah
* Fix remaing use of `checkDeviceTrust` Followup to #10663 * fix strict type-checking error
matrix-org/matrix-js-sdk#3287 and matrix-org/matrix-js-sdk#3303 added a new API called
getDeviceVerificationStatus. Let's use it.Hopefully this makes sense to review commit-by-commit.
The quality gate isn't quite met but there are cypress tests covering the places where coverage is lacking.
Fixes element-hq/element-web#25092 and element-hq/element-web#25093
This change is marked as an internal change (Task), so will not be included in the changelog.