Simplify references to VerificationRequest (#11045)

* Use new `VerificationRequest.getQRCodeBytes()`

* Use new `VerificationRequest.otherDeviceId`

* Remove references to `VerificationRequest.channel`

* Replace references to `VerificationRequest.{requesting,receiving}UserId`

Normally these are guarded by `request.initiatedByMe` so we can trivially
replace it with `request.otherUserId` or `client.getUserId()`. In one place we
actually need to apply some logic.

* increase test coverage

* Even more test coverage

* Even more test coverage
This commit is contained in:
Richard van der Hoff 2023-06-07 15:43:44 +01:00 committed by GitHub
parent ac2c9cef8d
commit 34439ee652
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 310 additions and 33 deletions

View file

@ -67,6 +67,7 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
const { member, request } = this.props;
const showSAS: boolean = request.otherPartySupportsMethod(verificationMethods.SAS);
const showQR: boolean = request.otherPartySupportsMethod(SCAN_QR_CODE_METHOD);
const qrCodeBytes = showQR ? request.getQRCodeBytes() : null;
const brand = SdkConfig.get().brand;
const noCommonMethodError: JSX.Element | null =
@ -85,11 +86,11 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
// HACK: This is a terrible idea.
let qrBlockDialog: JSX.Element | undefined;
let sasBlockDialog: JSX.Element | undefined;
if (showQR && request.qrCodeData) {
if (!!qrCodeBytes) {
qrBlockDialog = (
<div className="mx_VerificationPanel_QRPhase_startOption">
<p>{_t("Scan this unique code")}</p>
<VerificationQRCode qrCodeData={request.qrCodeData} />
<VerificationQRCode qrCodeBytes={qrCodeBytes} />
</div>
);
}
@ -133,7 +134,7 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
}
let qrBlock: JSX.Element | undefined;
if (showQR && request.qrCodeData) {
if (!!qrCodeBytes) {
qrBlock = (
<div className="mx_UserInfo_container">
<h3>{_t("Verify by scanning")}</h3>
@ -144,7 +145,7 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
</p>
<div className="mx_VerificationPanel_qrCode">
<VerificationQRCode qrCodeData={request.qrCodeData} />
<VerificationQRCode qrCodeBytes={qrCodeBytes} />
</div>
</div>
);
@ -201,7 +202,7 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
};
private getDevice(): DeviceInfo | null {
const deviceId = this.props.request && this.props.request.channel.deviceId;
const deviceId = this.props.request && this.props.request.otherDeviceId;
const userId = MatrixClientPeg.get().getUserId();
if (deviceId && userId) {
return MatrixClientPeg.get().getStoredDevice(userId, deviceId);
@ -275,12 +276,12 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
if (!device) {
// This can happen if the device is logged out while we're still showing verification
// UI for it.
logger.warn("Verified device we don't know about: " + this.props.request.channel.deviceId);
logger.warn("Verified device we don't know about: " + this.props.request.otherDeviceId);
description = _t("You've successfully verified your device!");
} else {
description = _t("You've successfully verified %(deviceName)s (%(deviceId)s)!", {
deviceName: device ? device.getDisplayName() : "",
deviceId: this.props.request.channel.deviceId,
deviceId: this.props.request.otherDeviceId,
});
}
} else {