Remove references to VerificationRequest (#11050)

* Update references to `VerificationRequestEvent`

* Update references to `Phase`

* update references to legacy `PHASE_*` constants

* Replace `request.canAccept` with `canAcceptVerificationRequest`

* Replace `VerificationRequest` with the interface throughout

* Minor strict type fixes

* Add a couple of tests
This commit is contained in:
Richard van der Hoff 2023-06-14 15:35:32 +01:00 committed by GitHub
parent 6486255f54
commit b9b93264b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 72 additions and 57 deletions

View file

@ -17,7 +17,7 @@ limitations under the License.
import React from "react";
import { ISecretStorageKeyInfo } from "matrix-js-sdk/src/crypto/api";
import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { VerificationRequest } from "matrix-js-sdk/src/crypto-api";
import { logger } from "matrix-js-sdk/src/logger";
import { _t } from "../../../languageHandler";

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import React from "react";
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { VerificationRequest } from "matrix-js-sdk/src/crypto-api";
import { User } from "matrix-js-sdk/src/models/user";
import { MatrixClientPeg } from "../../../MatrixClientPeg";

View file

@ -16,11 +16,8 @@ limitations under the License.
*/
import React, { useContext, useEffect, useState } from "react";
import {
Phase,
VerificationRequest,
VerificationRequestEvent,
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { VerificationPhase as Phase, VerificationRequestEvent } from "matrix-js-sdk/src/crypto-api";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { useTypedEventEmitter, useTypedEventEmitterState } from "../../../../hooks/useEventEmitter";

View file

@ -17,11 +17,7 @@ limitations under the License.
import React from "react";
import classNames from "classnames";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import {
Phase as VerificationPhase,
VerificationRequest,
VerificationRequestEvent,
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { VerificationPhase, VerificationRequest, VerificationRequestEvent } from "matrix-js-sdk/src/crypto-api";
import { EventType } from "matrix-js-sdk/src/@types/event";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";

View file

@ -18,9 +18,10 @@ import React from "react";
import { MatrixEvent, User } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger";
import {
Phase as VerificationPhase,
canAcceptVerificationRequest,
VerificationPhase,
VerificationRequestEvent,
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
} from "matrix-js-sdk/src/crypto-api";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import { _t } from "../../../languageHandler";
@ -139,7 +140,7 @@ export default class MKeyVerificationRequest extends React.Component<IProps> {
let subtitle: string;
let stateNode: JSX.Element | undefined;
if (!request.canAccept) {
if (!canAcceptVerificationRequest(request)) {
let stateLabel;
const accepted =
request.phase === VerificationPhase.Ready ||
@ -165,7 +166,7 @@ export default class MKeyVerificationRequest extends React.Component<IProps> {
const name = getNameForEventRoom(client, request.otherUserId, mxEvent.getRoomId()!);
title = _t("%(name)s wants to verify", { name });
subtitle = userLabelForEventRoom(client, request.otherUserId, mxEvent.getRoomId()!);
if (request.canAccept) {
if (canAcceptVerificationRequest(request)) {
stateNode = (
<div className="mx_cryptoEvent_buttons">
<AccessibleButton kind="danger" onClick={this.onRejectClicked}>

View file

@ -15,13 +15,7 @@ limitations under the License.
*/
import React, { useCallback, useEffect, useState } from "react";
import {
PHASE_REQUESTED,
PHASE_UNSENT,
Phase as VerificationPhase,
VerificationRequest,
VerificationRequestEvent,
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { VerificationPhase, VerificationRequest, VerificationRequestEvent } from "matrix-js-sdk/src/crypto-api";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { User } from "matrix-js-sdk/src/models/user";
@ -78,7 +72,11 @@ const EncryptionPanel: React.FC<IProps> = (props: IProps) => {
}, [verificationRequestPromise]);
const changeHandler = useCallback(() => {
// handle transitions -> cancelled for mismatches which fire a modal instead of showing a card
if (request && request.phase === VerificationPhase.Cancelled && MISMATCHES.includes(request.cancellationCode)) {
if (
request &&
request.phase === VerificationPhase.Cancelled &&
MISMATCHES.includes(request.cancellationCode ?? "")
) {
Modal.createDialog(ErrorDialog, {
headerImage: require("../../../../res/img/e2e/warning-deprecated.svg").default,
title: _t("Your messages are not secure"),
@ -139,7 +137,8 @@ const EncryptionPanel: React.FC<IProps> = (props: IProps) => {
const requested: boolean =
(!request && isRequesting) ||
(!!request && (phase === PHASE_REQUESTED || phase === PHASE_UNSENT || phase === undefined));
(!!request &&
(phase === VerificationPhase.Requested || phase === VerificationPhase.Unsent || phase === undefined));
const isSelfVerification = request ? request.isSelfVerification : member.userId === cli.getUserId();
if (!request || requested) {

View file

@ -24,7 +24,7 @@ import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { User } from "matrix-js-sdk/src/models/user";
import { Room } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { VerificationRequest } from "matrix-js-sdk/src/crypto-api";
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";

View file

@ -18,10 +18,10 @@ import React from "react";
import { verificationMethods } from "matrix-js-sdk/src/crypto";
import { SCAN_QR_CODE_METHOD } from "matrix-js-sdk/src/crypto/verification/QRCode";
import {
Phase,
VerificationRequest,
VerificationPhase as Phase,
VerificationRequestEvent,
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
} from "matrix-js-sdk/src/crypto-api";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { User } from "matrix-js-sdk/src/models/user";
import { logger } from "matrix-js-sdk/src/logger";
@ -202,7 +202,7 @@ export default class VerificationPanel extends React.PureComponent<IProps, IStat
};
private getDevice(): DeviceInfo | null {
const deviceId = this.props.request && this.props.request.otherDeviceId;
const deviceId = this.props.request?.otherDeviceId;
const userId = MatrixClientPeg.get().getUserId();
if (deviceId && userId) {
return MatrixClientPeg.get().getStoredDevice(userId, deviceId);

View file

@ -26,7 +26,7 @@ import {
PUSHER_ENABLED,
UNSTABLE_MSC3852_LAST_SEEN_UA,
} from "matrix-js-sdk/src/matrix";
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { VerificationRequest } from "matrix-js-sdk/src/crypto-api";
import { MatrixError } from "matrix-js-sdk/src/http-api";
import { logger } from "matrix-js-sdk/src/logger";
import { LocalNotificationSettings } from "matrix-js-sdk/src/@types/local_notifications";

View file

@ -16,9 +16,10 @@ limitations under the License.
import React from "react";
import {
canAcceptVerificationRequest,
VerificationRequest,
VerificationRequestEvent,
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
} from "matrix-js-sdk/src/crypto-api";
import { DeviceInfo } from "matrix-js-sdk/src/crypto/deviceinfo";
import { logger } from "matrix-js-sdk/src/logger";
@ -41,6 +42,7 @@ interface IProps {
}
interface IState {
/** number of seconds left in the timeout counter. Zero if there is no timeout. */
counter: number;
device?: DeviceInfo;
ip?: string;
@ -51,7 +53,7 @@ export default class VerificationRequestToast extends React.PureComponent<IProps
public constructor(props: IProps) {
super(props);
this.state = { counter: Math.ceil(props.request.timeout / 1000) };
this.state = { counter: Math.ceil((props.request.timeout ?? 0) / 1000) };
}
public async componentDidMount(): Promise<void> {
@ -93,7 +95,7 @@ export default class VerificationRequestToast extends React.PureComponent<IProps
private checkRequestIsPending = (): void => {
const { request } = this.props;
if (!request.canAccept) {
if (!canAcceptVerificationRequest(request)) {
ToastStore.sharedInstance().dismissToast(this.props.toastKey);
}
};

View file

@ -15,12 +15,7 @@ limitations under the License.
*/
import EventEmitter from "events";
import {
PHASE_DONE as VERIF_PHASE_DONE,
Phase as VerificationPhase,
VerificationRequest,
VerificationRequestEvent,
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { VerificationPhase, VerificationRequest, VerificationRequestEvent } from "matrix-js-sdk/src/crypto-api";
import { IKeyBackupInfo } from "matrix-js-sdk/src/crypto/keybackup";
import { ISecretStorageKeyInfo } from "matrix-js-sdk/src/crypto/api";
import { logger } from "matrix-js-sdk/src/logger";
@ -183,7 +178,7 @@ export class SetupEncryptionStore extends EventEmitter {
this.verificationRequest.off(VerificationRequestEvent.Change, this.onVerificationRequestChange);
this.verificationRequest = null;
this.emit("update");
} else if (this.verificationRequest?.phase === VERIF_PHASE_DONE) {
} else if (this.verificationRequest?.phase === VerificationPhase.Done) {
this.verificationRequest.off(VerificationRequestEvent.Change, this.onVerificationRequestChange);
this.verificationRequest = null;
// At this point, the verification has finished, we just need to wait for

View file

@ -18,7 +18,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import { User } from "matrix-js-sdk/src/models/user";
import { Room } from "matrix-js-sdk/src/models/room";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { VerificationRequest } from "matrix-js-sdk/src/crypto-api";
import { RightPanelPhases } from "./RightPanelStorePhases";

View file

@ -17,8 +17,7 @@ limitations under the License.
import { User } from "matrix-js-sdk/src/models/user";
import { verificationMethods as VerificationMethods } from "matrix-js-sdk/src/crypto";
import { MatrixClient, RoomMember } from "matrix-js-sdk/src/matrix";
import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
import { CrossSigningKey } from "matrix-js-sdk/src/crypto-api";
import { CrossSigningKey, VerificationRequest } from "matrix-js-sdk/src/crypto-api";
import dis from "./dispatcher/dispatcher";
import Modal from "./Modal";