From 24bda5602f877216f3c8fcba4a6ab760e0cbf512 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 24 Mar 2022 12:25:59 +0000 Subject: [PATCH] Strip relations when forwarding (#7929) --- .../views/dialogs/ForwardDialog.tsx | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/components/views/dialogs/ForwardDialog.tsx b/src/components/views/dialogs/ForwardDialog.tsx index e8e7db5572..d3f38fa9d1 100644 --- a/src/components/views/dialogs/ForwardDialog.tsx +++ b/src/components/views/dialogs/ForwardDialog.tsx @@ -16,10 +16,11 @@ limitations under the License. import React, { useEffect, useMemo, useState } from "react"; import classnames from "classnames"; -import { MatrixEvent } from "matrix-js-sdk/src/models/event"; +import { IContent, MatrixEvent } from "matrix-js-sdk/src/models/event"; import { Room } from "matrix-js-sdk/src/models/room"; import { MatrixClient } from "matrix-js-sdk/src/client"; import { RoomMember } from "matrix-js-sdk/src/models/room-member"; +import { EventType } from "matrix-js-sdk/src/@types/event"; import { _t } from "../../../languageHandler"; import dis from "../../../dispatcher/dispatcher"; @@ -60,7 +61,8 @@ interface IProps extends IDialogProps { interface IEntryProps { room: Room; - event: MatrixEvent; + type: EventType | string; + content: IContent; matrixClient: MatrixClient; onFinished(success: boolean): void; } @@ -72,7 +74,7 @@ enum SendState { Failed, } -const Entry: React.FC = ({ room, event, matrixClient: cli, onFinished }) => { +const Entry: React.FC = ({ room, type, content, matrixClient: cli, onFinished }) => { const [sendState, setSendState] = useState(SendState.CanSend); const jumpToRoom = (ev: ButtonEvent) => { @@ -87,7 +89,7 @@ const Entry: React.FC = ({ room, event, matrixClient: cli, onFinish const send = async () => { setSendState(SendState.Sending); try { - await cli.sendEvent(room.roomId, event.getType(), event.getContent()); + await cli.sendEvent(room.roomId, type, content); setSendState(SendState.Sent); } catch (e) { setSendState(SendState.Failed); @@ -161,11 +163,18 @@ const ForwardDialog: React.FC = ({ matrixClient: cli, event, permalinkCr cli.getProfileInfo(userId).then(info => setProfileInfo(info)); }, [cli, userId]); + const { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + "m.relates_to": _, // strip relations - in future we will attach a relation pointing at the original event + // We're taking a shallow copy here to avoid https://github.com/vector-im/element-web/issues/10924 + ...content + } = event.getContent(); + // For the message preview we fake the sender as ourselves const mockEvent = new MatrixEvent({ type: "m.room.message", sender: userId, - content: event.getContent(), + content, unsigned: { age: 97, }, @@ -258,7 +267,8 @@ const ForwardDialog: React.FC = ({ matrixClient: cli, event, permalinkCr ,