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
Show file tree
Hide file tree
Changes from 3 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
5 changes: 2 additions & 3 deletions src/ContentMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import dis from './dispatcher/dispatcher';
import * as sdk from './index';
import { _t } from './languageHandler';
import Modal from './Modal';
import RoomViewStore from './stores/RoomViewStore';
import Spinner from "./components/views/elements/Spinner";
import { Action } from "./dispatcher/actions";
import {
Expand All @@ -46,6 +45,7 @@ import { BlurhashEncoder } from "./BlurhashEncoder";
import SettingsStore from "./settings/SettingsStore";
import { decorateStartSendingTime, sendRoundTripMetric } from "./sendTimePerformanceMetrics";
import { TimelineRenderingType } from "./contexts/RoomContext";
import RoomViewStore from "./stores/RoomViewStore";

const MAX_WIDTH = 800;
const MAX_HEIGHT = 600;
Expand Down Expand Up @@ -456,8 +456,7 @@ export default class ContentMessages {
return;
}

const isQuoting = Boolean(RoomViewStore.getQuotingEvent());
if (isQuoting) {
if (context === TimelineRenderingType.Room && RoomViewStore.getQuotingEvent()) {
// FIXME: Using an import will result in Element crashing
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
const { finished } = Modal.createTrackedDialog<[boolean]>('Upload Reply Warning', '', QuestionDialog, {
Expand Down
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
3 changes: 1 addition & 2 deletions src/stores/RoomViewStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ class RoomViewStore extends Store<ActionPayload> {
// If currently viewed room does not match the room in which we wish to reply then change rooms
// this can happen when performing a search across all rooms
if (payload.context === TimelineRenderingType.Room) {
if (payload.event
&& payload.event.getRoomId() !== this.state.roomId) {
if (payload.event?.getRoomId() !== this.state.roomId) {
dis.dispatch<ViewRoomPayload>({
action: Action.ViewRoom,
room_id: payload.event.getRoomId(),
Expand Down