Fix issue with redacting via edit composer flow causing stuck editStates (#8184)

This commit is contained in:
Michael Telatynski 2022-03-29 13:33:11 +01:00 committed by GitHub
parent 69469e5a98
commit c3e02b21cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 10 deletions

20
src/Editing.ts Normal file
View file

@ -0,0 +1,20 @@
/*
Copyright 2022 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 { TimelineRenderingType } from "./contexts/RoomContext";
export const editorRoomKey = (roomId: string, context: TimelineRenderingType) => `mx_edit_room_${roomId}_${context}`;
export const editorStateKey = (eventId: string) => `mx_edit_state_${eventId}`;

View file

@ -53,6 +53,7 @@ import EditorStateTransfer from "../../utils/EditorStateTransfer";
import { Action } from '../../dispatcher/actions'; import { Action } from '../../dispatcher/actions';
import { getEventDisplayInfo } from "../../utils/EventUtils"; import { getEventDisplayInfo } from "../../utils/EventUtils";
import { IReadReceiptInfo } from "../views/rooms/ReadReceiptMarker"; import { IReadReceiptInfo } from "../views/rooms/ReadReceiptMarker";
import { editorRoomKey } from "../../Editing";
const CONTINUATION_MAX_INTERVAL = 5 * 60 * 1000; // 5 minutes const CONTINUATION_MAX_INTERVAL = 5 * 60 * 1000; // 5 minutes
const continuedTypes = [EventType.Sticker, EventType.RoomMessage]; const continuedTypes = [EventType.Sticker, EventType.RoomMessage];
@ -307,9 +308,10 @@ export default class MessagePanel extends React.Component<IProps, IState> {
const pendingEditItem = this.pendingEditItem; const pendingEditItem = this.pendingEditItem;
if (!this.props.editState && this.props.room && pendingEditItem) { if (!this.props.editState && this.props.room && pendingEditItem) {
const event = this.props.room.findEventById(pendingEditItem);
defaultDispatcher.dispatch({ defaultDispatcher.dispatch({
action: Action.EditEvent, action: Action.EditEvent,
event: this.props.room.findEventById(pendingEditItem), event: !event?.isRedacted() ? event : null,
timelineRenderingType: this.context.timelineRenderingType, timelineRenderingType: this.context.timelineRenderingType,
}); });
} }
@ -613,13 +615,15 @@ export default class MessagePanel extends React.Component<IProps, IState> {
if (!this.props.room) { if (!this.props.room) {
return undefined; return undefined;
} }
try { try {
return localStorage.getItem(`mx_edit_room_${this.props.room.roomId}_${this.context.timelineRenderingType}`); return localStorage.getItem(editorRoomKey(this.props.room.roomId, this.context.timelineRenderingType));
} catch (err) { } catch (err) {
logger.error(err); logger.error(err);
return undefined; return undefined;
} }
} }
private getEventTiles(): ReactNode[] { private getEventTiles(): ReactNode[] {
let i; let i;
@ -722,10 +726,8 @@ export default class MessagePanel extends React.Component<IProps, IState> {
): ReactNode[] { ): ReactNode[] {
const ret = []; const ret = [];
const isEditing = this.props.editState && const isEditing = this.props.editState?.getEvent().getId() === mxEv.getId();
this.props.editState.getEvent().getId() === mxEv.getId(); // local echoes have a fake date, which could even be yesterday. Treat them as 'today' for the date separators.
// local echoes have a fake date, which could even be yesterday. Treat them
// as 'today' for the date separators.
let ts1 = mxEv.getTs(); let ts1 = mxEv.getTs();
let eventDate = mxEv.getDate(); let eventDate = mxEv.getDate();
if (mxEv.status) { if (mxEv.status) {

View file

@ -366,7 +366,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
this.checkWidgets(this.state.room); this.checkWidgets(this.state.room);
}; };
private checkWidgets = (room) => { private checkWidgets = (room: Room): void => {
this.setState({ this.setState({
hasPinnedWidgets: WidgetLayoutStore.instance.hasPinnedWidgets(room), hasPinnedWidgets: WidgetLayoutStore.instance.hasPinnedWidgets(room),
mainSplitContentType: this.getMainSplitContentType(room), mainSplitContentType: this.getMainSplitContentType(room),
@ -374,7 +374,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
}); });
}; };
private getMainSplitContentType = (room) => { private getMainSplitContentType = (room: Room) => {
if (SettingsStore.getValue("feature_voice_rooms") && room.isCallRoom()) { if (SettingsStore.getValue("feature_voice_rooms") && room.isCallRoom()) {
return MainSplitContentType.Video; return MainSplitContentType.Video;
} }

View file

@ -47,6 +47,7 @@ import { ComposerType } from "../../../dispatcher/payloads/ComposerInsertPayload
import { getSlashCommand, isSlashCommand, runSlashCommand, shouldSendAnyway } from "../../../editor/commands"; import { getSlashCommand, isSlashCommand, runSlashCommand, shouldSendAnyway } from "../../../editor/commands";
import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts"; import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
import { PosthogAnalytics } from "../../../PosthogAnalytics"; import { PosthogAnalytics } from "../../../PosthogAnalytics";
import { editorRoomKey, editorStateKey } from "../../../Editing";
function getHtmlReplyFallback(mxEvent: MatrixEvent): string { function getHtmlReplyFallback(mxEvent: MatrixEvent): string {
const html = mxEvent.getContent().formatted_body; const html = mxEvent.getContent().formatted_body;
@ -224,11 +225,11 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
} }
private get editorRoomKey(): string { private get editorRoomKey(): string {
return `mx_edit_room_${this.getRoom().roomId}_${this.context.timelineRenderingType}`; return editorRoomKey(this.props.editState.getEvent().getRoomId(), this.context.timelineRenderingType);
} }
private get editorStateKey(): string { private get editorStateKey(): string {
return `mx_edit_state_${this.props.editState.getEvent().getId()}`; return editorStateKey(this.props.editState.getEvent().getId());
} }
private get events(): MatrixEvent[] { private get events(): MatrixEvent[] {
@ -316,6 +317,9 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
this.cancelPreviousPendingEdit(); this.cancelPreviousPendingEdit();
createRedactEventDialog({ createRedactEventDialog({
mxEvent: editedEvent, mxEvent: editedEvent,
onCloseDialog: () => {
this.cancelEdit();
},
}); });
return; return;
} }