Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Use getShowSasCallbacks() and getReciprocateQrCodeCallbacks() #11015

Merged
merged 4 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/components/views/right_panel/VerificationPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ limitations under the License.

import React from "react";
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 {
Phase,
VerificationRequest,
VerificationRequestEvent,
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
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 { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
import { ShowQrCodeCallbacks, ShowSasCallbacks, VerifierEvent } from "matrix-js-sdk/src/crypto-api/verification";
Expand Down Expand Up @@ -400,8 +399,8 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat

private updateVerifierState = (): void => {
const { request } = this.props;
const sasEvent = (request.verifier as SAS).sasEvent;
const reciprocateQREvent = (request.verifier as ReciprocateQRCode).reciprocateQREvent;
const sasEvent = request.verifier.getShowSasCallbacks();
const reciprocateQREvent = request.verifier.getShowQrCodeCallbacks();
request.verifier?.off(VerifierEvent.ShowSas, this.updateVerifierState);
request.verifier?.off(VerifierEvent.ShowReciprocateQr, this.updateVerifierState);
this.setState({ sasEvent, reciprocateQREvent });
Expand All @@ -428,8 +427,8 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
const { request } = this.props;
request.on(VerificationRequestEvent.Change, this.onRequestChange);
if (request.verifier) {
const sasEvent = (request.verifier as SAS).sasEvent;
const reciprocateQREvent = (request.verifier as ReciprocateQRCode).reciprocateQREvent;
const sasEvent = request.verifier.getShowSasCallbacks();
const reciprocateQREvent = request.verifier.getShowQrCodeCallbacks();
this.setState({ sasEvent, reciprocateQREvent });
}
this.onRequestChange();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
VerifierEvent,
VerifierEventHandlerMap,
} 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 VerificationPanel from "../../../../src/components/views/right_panel/VerificationPanel";
Expand Down Expand Up @@ -78,7 +77,7 @@ describe("<VerificationPanel />", () => {

// fire the ShowSas event
const sasEvent = makeMockSasCallbacks();
(mockVerifier as unknown as SAS).sasEvent = sasEvent;
mockVerifier.getShowSasCallbacks.mockReturnValue(sasEvent);
act(() => {
mockVerifier.emit(VerifierEvent.ShowSas, sasEvent);
});
Expand Down Expand Up @@ -119,6 +118,8 @@ function makeMockVerifier(): Mocked<VerificationBase> {
Object.assign(verifier, {
cancel: jest.fn(),
verify: jest.fn(),
getShowSasCallbacks: jest.fn(),
getShowQrCodeCallbacks: jest.fn(),
});
return verifier as unknown as Mocked<VerificationBase>;
}
Expand Down