Stop displaying verification done messages in timeline (#11932)

* Stop displaying verification done messages in timeline

* i18n fixes
This commit is contained in:
Andy Balaam 2023-12-01 09:12:38 +00:00 committed by GitHub
parent f07a8800d3
commit 926907309a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 0 additions and 326 deletions

View file

@ -1,144 +0,0 @@
/*
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import React from "react";
import classNames from "classnames";
import { MatrixEvent, EventType } from "matrix-js-sdk/src/matrix";
import { VerificationPhase, VerificationRequest, VerificationRequestEvent } from "matrix-js-sdk/src/crypto-api";
import { CryptoEvent } from "matrix-js-sdk/src/crypto";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
import { _t } from "../../../languageHandler";
import { getNameForEventRoom, userLabelForEventRoom } from "../../../utils/KeyVerificationStateObserver";
import EventTileBubble from "./EventTileBubble";
interface IProps {
/* the MatrixEvent to show */
mxEvent: MatrixEvent;
timestamp?: JSX.Element;
}
export default class MKeyVerificationConclusion extends React.Component<IProps> {
public constructor(props: IProps) {
super(props);
}
public componentDidMount(): void {
const request = this.props.mxEvent.verificationRequest;
if (request) {
request.on(VerificationRequestEvent.Change, this.onRequestChanged);
}
MatrixClientPeg.safeGet().on(CryptoEvent.UserTrustStatusChanged, this.onTrustChanged);
}
public componentWillUnmount(): void {
const request = this.props.mxEvent.verificationRequest;
if (request) {
request.off(VerificationRequestEvent.Change, this.onRequestChanged);
}
const cli = MatrixClientPeg.get();
if (cli) {
cli.removeListener(CryptoEvent.UserTrustStatusChanged, this.onTrustChanged);
}
}
private onRequestChanged = (): void => {
this.forceUpdate();
};
private onTrustChanged = (userId: string): void => {
const { mxEvent } = this.props;
const request = mxEvent.verificationRequest;
if (!request || request.otherUserId !== userId) {
return;
}
this.forceUpdate();
};
public static shouldRender(mxEvent: MatrixEvent, request?: VerificationRequest): boolean {
// normally should not happen
if (!request) {
return false;
}
// .cancel event that was sent after the verification finished, ignore
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.phase !== VerificationPhase.Done) {
return false;
}
// request hasn't concluded yet
if (request.pending) {
return false;
}
// User isn't actually verified
if (!MatrixClientPeg.safeGet().checkUserTrust(request.otherUserId).isCrossSigningVerified()) {
return false;
}
return true;
}
public render(): JSX.Element | null {
const { mxEvent } = this.props;
const request = mxEvent.verificationRequest!;
if (!MKeyVerificationConclusion.shouldRender(mxEvent, request)) {
return null;
}
const client = MatrixClientPeg.safeGet();
const myUserId = client.getUserId();
let title: string | undefined;
if (request.phase === VerificationPhase.Done) {
title = _t("timeline|m.key.verification.done", {
name: getNameForEventRoom(client, request.otherUserId, mxEvent.getRoomId()!),
});
} else if (request.phase === VerificationPhase.Cancelled) {
const userId = request.cancellingUserId;
if (userId === myUserId) {
title = _t("timeline|m.key.verification.cancel|you_cancelled", {
name: getNameForEventRoom(client, request.otherUserId, mxEvent.getRoomId()!),
});
} else if (userId) {
title = _t("timeline|m.key.verification.cancel|user_cancelled", {
name: getNameForEventRoom(client, userId, mxEvent.getRoomId()!),
});
}
}
if (title) {
const classes = classNames("mx_cryptoEvent mx_cryptoEvent_icon", {
mx_cryptoEvent_icon_verified: request.phase === VerificationPhase.Done,
});
return (
<EventTileBubble
className={classes}
title={title}
subtitle={userLabelForEventRoom(client, request.otherUserId, mxEvent.getRoomId()!)}
timestamp={this.props.timestamp}
/>
);
}
return null;
}
}

View file

@ -32,7 +32,6 @@ import LegacyCallEventGrouper from "../components/structures/LegacyCallEventGrou
import { EventTileProps } from "../components/views/rooms/EventTile";
import { TimelineRenderingType } from "../contexts/RoomContext";
import MessageEvent from "../components/views/messages/MessageEvent";
import MKeyVerificationConclusion from "../components/views/messages/MKeyVerificationConclusion";
import LegacyCallEvent from "../components/views/messages/LegacyCallEvent";
import { CallEvent } from "../components/views/messages/CallEvent";
import TextualEvent from "../components/views/messages/TextualEvent";
@ -87,7 +86,6 @@ type FactoryProps = Omit<EventTileTypeProps, "ref">;
type Factory<X = FactoryProps> = (ref: Optional<React.RefObject<any>>, props: X) => JSX.Element;
export const MessageEventFactory: Factory = (ref, props) => <MessageEvent ref={ref} {...props} />;
const KeyVerificationConclFactory: Factory = (ref, props) => <MKeyVerificationConclusion ref={ref} {...props} />;
const LegacyCallEventFactory: Factory<FactoryProps & { callEventGrouper: LegacyCallEventGrouper }> = (ref, props) => (
<LegacyCallEvent ref={ref} {...props} />
);
@ -108,8 +106,6 @@ const EVENT_TILE_TYPES = new Map<string, Factory>([
[M_POLL_START.altName, MessageEventFactory],
[M_POLL_END.name, MessageEventFactory],
[M_POLL_END.altName, MessageEventFactory],
[EventType.KeyVerificationCancel, KeyVerificationConclFactory],
[EventType.KeyVerificationDone, KeyVerificationConclFactory],
[EventType.CallInvite, LegacyCallEventFactory as Factory], // note that this requires a special factory type
]);
@ -205,23 +201,6 @@ export function pickFactory(
return VerificationReqFactory;
}
}
} else if (evType === EventType.KeyVerificationDone) {
// these events are sent by both parties during verification, but we only want to render one
// tile once the verification concludes, so filter out the one from the other party.
const me = cli.getUserId();
if (mxEvent.getSender() !== me) {
return noEventFactoryFactory();
}
}
if (evType === EventType.KeyVerificationCancel || evType === EventType.KeyVerificationDone) {
// sometimes MKeyVerificationConclusion declines to render. Jankily decline to render and
// fall back to showing hidden events, if we're viewing hidden events
// XXX: This is extremely a hack. Possibly these components should have an interface for
// declining to render?
if (!MKeyVerificationConclusion.shouldRender(mxEvent, mxEvent.verificationRequest)) {
return noEventFactoryFactory();
}
}
if (evType === EventType.RoomCreate) {

View file

@ -3261,11 +3261,6 @@
"sent": "%(senderDisplayName)s sent an image.",
"show_image": "Show image"
},
"m.key.verification.cancel": {
"user_cancelled": "%(name)s cancelled verifying",
"you_cancelled": "You cancelled verifying %(name)s"
},
"m.key.verification.done": "You verified %(name)s",
"m.key.verification.request": {
"user_wants_to_verify": "%(name)s wants to verify",
"you_started": "You sent a verification request"