Improve typing around event emitter handlers (#7816)

This commit is contained in:
Michael Telatynski 2022-02-22 12:18:08 +00:00 committed by GitHub
parent 213b32bf14
commit 7fa01ffb06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
79 changed files with 548 additions and 471 deletions

View file

@ -28,6 +28,7 @@ import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { logger } from "matrix-js-sdk/src/logger";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import dis from '../../../dispatcher/dispatcher';
import Modal from '../../../Modal';
@ -1275,15 +1276,15 @@ export const useDevices = (userId: string) => {
if (_userId !== userId) return;
updateDevices();
};
cli.on("crypto.devicesUpdated", onDevicesUpdated);
cli.on("deviceVerificationChanged", onDeviceVerificationChanged);
cli.on("userTrustStatusChanged", onUserTrustStatusChanged);
cli.on(CryptoEvent.DevicesUpdated, onDevicesUpdated);
cli.on(CryptoEvent.DeviceVerificationChanged, onDeviceVerificationChanged);
cli.on(CryptoEvent.UserTrustStatusChanged, onUserTrustStatusChanged);
// Handle being unmounted
return () => {
cancel = true;
cli.removeListener("crypto.devicesUpdated", onDevicesUpdated);
cli.removeListener("deviceVerificationChanged", onDeviceVerificationChanged);
cli.removeListener("userTrustStatusChanged", onUserTrustStatusChanged);
cli.removeListener(CryptoEvent.DevicesUpdated, onDevicesUpdated);
cli.removeListener(CryptoEvent.DeviceVerificationChanged, onDeviceVerificationChanged);
cli.removeListener(CryptoEvent.UserTrustStatusChanged, onUserTrustStatusChanged);
};
}, [cli, userId]);

View file

@ -16,11 +16,15 @@ limitations under the License.
import React from "react";
import { verificationMethods } from 'matrix-js-sdk/src/crypto';
import { SCAN_QR_CODE_METHOD, ReciprocateQRCode } from "matrix-js-sdk/src/crypto/verification/QRCode";
import { VerificationRequest, Phase } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { QrCodeEvent, ReciprocateQRCode, 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 { SAS, SasEvent } from "matrix-js-sdk/src/crypto/verification/SAS";
import { logger } from "matrix-js-sdk/src/logger";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
@ -357,8 +361,8 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
const { request } = this.props;
const sasEvent = (request.verifier as SAS).sasEvent;
const reciprocateQREvent = (request.verifier as ReciprocateQRCode).reciprocateQREvent;
request.verifier.off('show_sas', this.updateVerifierState);
request.verifier.off('show_reciprocate_qr', this.updateVerifierState);
request.verifier.off(SasEvent.ShowSas, this.updateVerifierState);
request.verifier.off(QrCodeEvent.ShowReciprocateQr, this.updateVerifierState);
this.setState({ sasEvent, reciprocateQREvent });
};
@ -367,8 +371,8 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
const hadVerifier = this.hasVerifier;
this.hasVerifier = !!request.verifier;
if (!hadVerifier && this.hasVerifier) {
request.verifier.on('show_sas', this.updateVerifierState);
request.verifier.on('show_reciprocate_qr', this.updateVerifierState);
request.verifier.on(SasEvent.ShowSas, this.updateVerifierState);
request.verifier.on(QrCodeEvent.ShowReciprocateQr, this.updateVerifierState);
try {
// on the requester side, this is also awaited in startSAS,
// but that's ok as verify should return the same promise.
@ -381,7 +385,7 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
public componentDidMount() {
const { request } = this.props;
request.on("change", this.onRequestChange);
request.on(VerificationRequestEvent.Change, this.onRequestChange);
if (request.verifier) {
const sasEvent = (request.verifier as SAS).sasEvent;
const reciprocateQREvent = (request.verifier as ReciprocateQRCode).reciprocateQREvent;
@ -393,9 +397,9 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
public componentWillUnmount() {
const { request } = this.props;
if (request.verifier) {
request.verifier.off('show_sas', this.updateVerifierState);
request.verifier.off('show_reciprocate_qr', this.updateVerifierState);
request.verifier.off(SasEvent.ShowSas, this.updateVerifierState);
request.verifier.off(QrCodeEvent.ShowReciprocateQr, this.updateVerifierState);
}
request.off("change", this.onRequestChange);
request.off(VerificationRequestEvent.Change, this.onRequestChange);
}
}