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:
Richard van der Hoff 2023-06-06 09:27:53 +01:00 committed by GitHub
parent 6fa005dcfc
commit 2801afe570
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 210 additions and 35 deletions

View file

@ -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…");