mirror of https://github.com/vector-im/riot-web
Use `getShowSasCallbacks()` and `getReciprocateQrCodeCallbacks()` (#11015)
* Use `getShowSasCallbacks()` and `getShowQrCodeCallbacks()` ... instead of type-casting * Update method names These methods got renamed in the js-sdk PR * Fix strict typing errorspull/28217/head
parent
b2452a45ff
commit
4c73903274
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { verificationMethods } from "matrix-js-sdk/src/crypto";
|
import { verificationMethods } from "matrix-js-sdk/src/crypto";
|
||||||
import { ReciprocateQRCode, SCAN_QR_CODE_METHOD } from "matrix-js-sdk/src/crypto/verification/QRCode";
|
import { SCAN_QR_CODE_METHOD } from "matrix-js-sdk/src/crypto/verification/QRCode";
|
||||||
import {
|
import {
|
||||||
Phase,
|
Phase,
|
||||||
VerificationRequest,
|
VerificationRequest,
|
||||||
|
@ -24,7 +24,6 @@ import {
|
||||||
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
||||||
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
||||||
import { User } from "matrix-js-sdk/src/models/user";
|
import { User } from "matrix-js-sdk/src/models/user";
|
||||||
import { SAS } from "matrix-js-sdk/src/crypto/verification/SAS";
|
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
|
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
|
||||||
import { ShowQrCodeCallbacks, ShowSasCallbacks, VerifierEvent } from "matrix-js-sdk/src/crypto-api/verification";
|
import { ShowQrCodeCallbacks, ShowSasCallbacks, VerifierEvent } from "matrix-js-sdk/src/crypto-api/verification";
|
||||||
|
@ -49,10 +48,10 @@ interface IProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
sasEvent?: ShowSasCallbacks;
|
sasEvent: ShowSasCallbacks | null;
|
||||||
emojiButtonClicked?: boolean;
|
emojiButtonClicked?: boolean;
|
||||||
reciprocateButtonClicked?: boolean;
|
reciprocateButtonClicked?: boolean;
|
||||||
reciprocateQREvent?: ShowQrCodeCallbacks;
|
reciprocateQREvent: ShowQrCodeCallbacks | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class VerificationPanel extends React.PureComponent<IProps, IState> {
|
export default class VerificationPanel extends React.PureComponent<IProps, IState> {
|
||||||
|
@ -60,7 +59,7 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
|
||||||
|
|
||||||
public constructor(props: IProps) {
|
public constructor(props: IProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {};
|
this.state = { sasEvent: null, reciprocateQREvent: null };
|
||||||
this.hasVerifier = false;
|
this.hasVerifier = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,11 +398,12 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
|
||||||
};
|
};
|
||||||
|
|
||||||
private updateVerifierState = (): void => {
|
private updateVerifierState = (): void => {
|
||||||
const { request } = this.props;
|
// this method is only called once we know there is a verifier.
|
||||||
const sasEvent = (request.verifier as SAS).sasEvent;
|
const verifier = this.props.request.verifier!;
|
||||||
const reciprocateQREvent = (request.verifier as ReciprocateQRCode).reciprocateQREvent;
|
const sasEvent = verifier.getShowSasCallbacks();
|
||||||
request.verifier?.off(VerifierEvent.ShowSas, this.updateVerifierState);
|
const reciprocateQREvent = verifier.getReciprocateQrCodeCallbacks();
|
||||||
request.verifier?.off(VerifierEvent.ShowReciprocateQr, this.updateVerifierState);
|
verifier.off(VerifierEvent.ShowSas, this.updateVerifierState);
|
||||||
|
verifier.off(VerifierEvent.ShowReciprocateQr, this.updateVerifierState);
|
||||||
this.setState({ sasEvent, reciprocateQREvent });
|
this.setState({ sasEvent, reciprocateQREvent });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -428,8 +428,8 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
|
||||||
const { request } = this.props;
|
const { request } = this.props;
|
||||||
request.on(VerificationRequestEvent.Change, this.onRequestChange);
|
request.on(VerificationRequestEvent.Change, this.onRequestChange);
|
||||||
if (request.verifier) {
|
if (request.verifier) {
|
||||||
const sasEvent = (request.verifier as SAS).sasEvent;
|
const sasEvent = request.verifier.getShowSasCallbacks();
|
||||||
const reciprocateQREvent = (request.verifier as ReciprocateQRCode).reciprocateQREvent;
|
const reciprocateQREvent = request.verifier.getReciprocateQrCodeCallbacks();
|
||||||
this.setState({ sasEvent, reciprocateQREvent });
|
this.setState({ sasEvent, reciprocateQREvent });
|
||||||
}
|
}
|
||||||
this.onRequestChange();
|
this.onRequestChange();
|
||||||
|
|
|
@ -31,7 +31,6 @@ import {
|
||||||
VerifierEvent,
|
VerifierEvent,
|
||||||
VerifierEventHandlerMap,
|
VerifierEventHandlerMap,
|
||||||
} from "matrix-js-sdk/src/crypto-api/verification";
|
} from "matrix-js-sdk/src/crypto-api/verification";
|
||||||
import { SAS } from "matrix-js-sdk/src/crypto/verification/SAS";
|
|
||||||
import { IVerificationChannel } from "matrix-js-sdk/src/crypto/verification/request/Channel";
|
import { IVerificationChannel } from "matrix-js-sdk/src/crypto/verification/request/Channel";
|
||||||
|
|
||||||
import VerificationPanel from "../../../../src/components/views/right_panel/VerificationPanel";
|
import VerificationPanel from "../../../../src/components/views/right_panel/VerificationPanel";
|
||||||
|
@ -78,7 +77,7 @@ describe("<VerificationPanel />", () => {
|
||||||
|
|
||||||
// fire the ShowSas event
|
// fire the ShowSas event
|
||||||
const sasEvent = makeMockSasCallbacks();
|
const sasEvent = makeMockSasCallbacks();
|
||||||
(mockVerifier as unknown as SAS).sasEvent = sasEvent;
|
mockVerifier.getShowSasCallbacks.mockReturnValue(sasEvent);
|
||||||
act(() => {
|
act(() => {
|
||||||
mockVerifier.emit(VerifierEvent.ShowSas, sasEvent);
|
mockVerifier.emit(VerifierEvent.ShowSas, sasEvent);
|
||||||
});
|
});
|
||||||
|
@ -119,6 +118,8 @@ function makeMockVerifier(): Mocked<VerificationBase> {
|
||||||
Object.assign(verifier, {
|
Object.assign(verifier, {
|
||||||
cancel: jest.fn(),
|
cancel: jest.fn(),
|
||||||
verify: jest.fn(),
|
verify: jest.fn(),
|
||||||
|
getShowSasCallbacks: jest.fn(),
|
||||||
|
getReciprocateQrCodeCallbacks: jest.fn(),
|
||||||
});
|
});
|
||||||
return verifier as unknown as Mocked<VerificationBase>;
|
return verifier as unknown as Mocked<VerificationBase>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue