Inline VerificationRequest.{invalid,ready,started,done,cancelled}
(#11013)
* Inline `VerificationRequest.{invalid,ready,started,done,cancelled}` These methods are all just shortcuts for checks on `phase`, so let's get rid of them * update test * Add some more tests * even more coverage * fix tests
This commit is contained in:
parent
6fa005dcfc
commit
2801afe570
7 changed files with 210 additions and 35 deletions
|
@ -18,6 +18,7 @@ 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";
|
||||
|
@ -78,11 +79,11 @@ export default class MKeyVerificationConclusion extends React.Component<IProps>
|
|||
return false;
|
||||
}
|
||||
// .cancel event that was sent after the verification finished, ignore
|
||||
if (mxEvent.getType() === EventType.KeyVerificationCancel && !request.cancelled) {
|
||||
if (mxEvent.getType() === EventType.KeyVerificationCancel && request.phase !== VerificationPhase.Cancelled) {
|
||||
return false;
|
||||
}
|
||||
// .done event that was sent after the verification cancelled, ignore
|
||||
if (mxEvent.getType() === EventType.KeyVerificationDone && !request.done) {
|
||||
if (mxEvent.getType() === EventType.KeyVerificationDone && request.phase !== VerificationPhase.Done) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -112,11 +113,11 @@ export default class MKeyVerificationConclusion extends React.Component<IProps>
|
|||
|
||||
let title: string | undefined;
|
||||
|
||||
if (request.done) {
|
||||
if (request.phase === VerificationPhase.Done) {
|
||||
title = _t("You verified %(name)s", {
|
||||
name: getNameForEventRoom(client, request.otherUserId, mxEvent.getRoomId()!),
|
||||
});
|
||||
} else if (request.cancelled) {
|
||||
} else if (request.phase === VerificationPhase.Cancelled) {
|
||||
const userId = request.cancellingUserId;
|
||||
if (userId === myUserId) {
|
||||
title = _t("You cancelled verifying %(name)s", {
|
||||
|
@ -131,7 +132,7 @@ export default class MKeyVerificationConclusion extends React.Component<IProps>
|
|||
|
||||
if (title) {
|
||||
const classes = classNames("mx_cryptoEvent mx_cryptoEvent_icon", {
|
||||
mx_cryptoEvent_icon_verified: request.done,
|
||||
mx_cryptoEvent_icon_verified: request.phase === VerificationPhase.Done,
|
||||
});
|
||||
return (
|
||||
<EventTileBubble
|
||||
|
|
|
@ -17,7 +17,10 @@ limitations under the License.
|
|||
import React from "react";
|
||||
import { MatrixEvent, User } from "matrix-js-sdk/src/matrix";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { VerificationRequestEvent } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
||||
import {
|
||||
Phase as VerificationPhase,
|
||||
VerificationRequestEvent,
|
||||
} from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest";
|
||||
|
||||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||
import { _t } from "../../../languageHandler";
|
||||
|
@ -128,7 +131,7 @@ export default class MKeyVerificationRequest extends React.Component<IProps> {
|
|||
const { mxEvent } = this.props;
|
||||
const request = mxEvent.verificationRequest;
|
||||
|
||||
if (!request || request.invalid) {
|
||||
if (!request || request.phase === VerificationPhase.Unsent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -138,14 +141,17 @@ export default class MKeyVerificationRequest extends React.Component<IProps> {
|
|||
|
||||
if (!request.canAccept) {
|
||||
let stateLabel;
|
||||
const accepted = request.ready || request.started || request.done;
|
||||
const accepted =
|
||||
request.phase === VerificationPhase.Ready ||
|
||||
request.phase === VerificationPhase.Started ||
|
||||
request.phase === VerificationPhase.Done;
|
||||
if (accepted) {
|
||||
stateLabel = (
|
||||
<AccessibleButton onClick={this.openRequest}>
|
||||
{this.acceptedLabel(request.receivingUserId)}
|
||||
</AccessibleButton>
|
||||
);
|
||||
} else if (request.cancelled) {
|
||||
} else if (request.phase === VerificationPhase.Cancelled) {
|
||||
stateLabel = this.cancelledLabel(request.cancellingUserId!);
|
||||
} else if (request.accepting) {
|
||||
stateLabel = _t("Accepting…");
|
||||
|
|
|
@ -18,6 +18,7 @@ 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";
|
||||
|
@ -76,7 +77,7 @@ 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.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"),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue