Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Strip relations when forwarding #7929

Merged
merged 4 commits into from
Mar 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/components/views/dialogs/ForwardDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -62,7 +63,8 @@ interface IProps extends IDialogProps {

interface IEntryProps {
room: Room;
event: MatrixEvent;
type: EventType | string;
content: IContent;
matrixClient: MatrixClient;
onFinished(success: boolean): void;
}
Expand All @@ -74,7 +76,7 @@ enum SendState {
Failed,
}

const Entry: React.FC<IEntryProps> = ({ room, event, matrixClient: cli, onFinished }) => {
const Entry: React.FC<IEntryProps> = ({ room, type, content, matrixClient: cli, onFinished }) => {
const [sendState, setSendState] = useState<SendState>(SendState.CanSend);

const jumpToRoom = (ev: ButtonEvent) => {
Expand All @@ -89,7 +91,7 @@ const Entry: React.FC<IEntryProps> = ({ 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);
Expand Down Expand Up @@ -163,11 +165,18 @@ const ForwardDialog: React.FC<IProps> = ({ 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,
},
Expand Down Expand Up @@ -264,7 +273,8 @@ const ForwardDialog: React.FC<IProps> = ({ matrixClient: cli, event, permalinkCr
<Entry
key={room.roomId}
room={room}
event={event}
type={event.getType()}
content={content}
matrixClient={cli}
onFinished={onFinished}
/>,
Expand Down