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

Commit fe276ab

Browse files
committed
Fix issue with redacting via edit composer flow causing stuck editStates
1 parent a3e5231 commit fe276ab

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

src/Editing.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { TimelineRenderingType } from "./contexts/RoomContext";
18+
19+
export const editorRoomKey = (roomId: string, context: TimelineRenderingType) => `mx_edit_room_${roomId}_${context}`;
20+
export const editorStateKey = (eventId: string) => `mx_edit_state_${eventId}`;

src/components/structures/MessagePanel.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import EditorStateTransfer from "../../utils/EditorStateTransfer";
5353
import { Action } from '../../dispatcher/actions';
5454
import { getEventDisplayInfo } from "../../utils/EventUtils";
5555
import { IReadReceiptInfo } from "../views/rooms/ReadReceiptMarker";
56+
import { editorRoomKey } from "../../Editing";
5657

5758
const CONTINUATION_MAX_INTERVAL = 5 * 60 * 1000; // 5 minutes
5859
const continuedTypes = [EventType.Sticker, EventType.RoomMessage];
@@ -307,9 +308,10 @@ export default class MessagePanel extends React.Component<IProps, IState> {
307308

308309
const pendingEditItem = this.pendingEditItem;
309310
if (!this.props.editState && this.props.room && pendingEditItem) {
311+
const event = this.props.room.findEventById(pendingEditItem);
310312
defaultDispatcher.dispatch({
311313
action: Action.EditEvent,
312-
event: this.props.room.findEventById(pendingEditItem),
314+
event: !event?.isRedacted() ? event : null,
313315
timelineRenderingType: this.context.timelineRenderingType,
314316
});
315317
}
@@ -613,13 +615,15 @@ export default class MessagePanel extends React.Component<IProps, IState> {
613615
if (!this.props.room) {
614616
return undefined;
615617
}
618+
616619
try {
617-
return localStorage.getItem(`mx_edit_room_${this.props.room.roomId}_${this.context.timelineRenderingType}`);
620+
return localStorage.getItem(editorRoomKey(this.props.room.roomId, this.context.timelineRenderingType));
618621
} catch (err) {
619622
logger.error(err);
620623
return undefined;
621624
}
622625
}
626+
623627
private getEventTiles(): ReactNode[] {
624628
let i;
625629

@@ -722,10 +726,8 @@ export default class MessagePanel extends React.Component<IProps, IState> {
722726
): ReactNode[] {
723727
const ret = [];
724728

725-
const isEditing = this.props.editState &&
726-
this.props.editState.getEvent().getId() === mxEv.getId();
727-
// local echoes have a fake date, which could even be yesterday. Treat them
728-
// as 'today' for the date separators.
729+
const isEditing = this.props.editState?.getEvent().getId() === mxEv.getId();
730+
// local echoes have a fake date, which could even be yesterday. Treat them as 'today' for the date separators.
729731
let ts1 = mxEv.getTs();
730732
let eventDate = mxEv.getDate();
731733
if (mxEv.status) {

src/components/structures/RoomView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,15 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
366366
this.checkWidgets(this.state.room);
367367
};
368368

369-
private checkWidgets = (room) => {
369+
private checkWidgets = (room: Room): void => {
370370
this.setState({
371371
hasPinnedWidgets: WidgetLayoutStore.instance.hasPinnedWidgets(room),
372372
mainSplitContentType: this.getMainSplitContentType(room),
373373
showApps: this.shouldShowApps(room),
374374
});
375375
};
376376

377-
private getMainSplitContentType = (room) => {
377+
private getMainSplitContentType = (room: Room) => {
378378
if (SettingsStore.getValue("feature_voice_rooms") && room.isCallRoom()) {
379379
return MainSplitContentType.Video;
380380
}

src/components/views/rooms/EditMessageComposer.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { ComposerType } from "../../../dispatcher/payloads/ComposerInsertPayload
4747
import { getSlashCommand, isSlashCommand, runSlashCommand, shouldSendAnyway } from "../../../editor/commands";
4848
import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
4949
import { PosthogAnalytics } from "../../../PosthogAnalytics";
50+
import { editorRoomKey, editorStateKey } from "../../../Editing";
5051

5152
function getHtmlReplyFallback(mxEvent: MatrixEvent): string {
5253
const html = mxEvent.getContent().formatted_body;
@@ -224,11 +225,11 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
224225
}
225226

226227
private get editorRoomKey(): string {
227-
return `mx_edit_room_${this.getRoom().roomId}_${this.context.timelineRenderingType}`;
228+
return editorRoomKey(this.props.editState.getEvent().getRoomId(), this.context.timelineRenderingType);
228229
}
229230

230231
private get editorStateKey(): string {
231-
return `mx_edit_state_${this.props.editState.getEvent().getId()}`;
232+
return editorStateKey(this.props.editState.getEvent().getId());
232233
}
233234

234235
private get events(): MatrixEvent[] {
@@ -316,6 +317,9 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
316317
this.cancelPreviousPendingEdit();
317318
createRedactEventDialog({
318319
mxEvent: editedEvent,
320+
onCloseDialog: () => {
321+
this.cancelEdit();
322+
},
319323
});
320324
return;
321325
}

0 commit comments

Comments
 (0)