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

Fix editing event from search room view #11992

Merged
merged 10 commits into from
Dec 19, 2023
31 changes: 26 additions & 5 deletions src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ export interface IRoomState {
initialEventScrollIntoView?: boolean;
replyToEvent?: MatrixEvent;
numUnreadMessages: number;
/**
* The state of an ongoing search if there is one.
*/
search?: ISearchInfo;
callState?: CallState;
activeCall: Call | null;
Expand Down Expand Up @@ -1208,12 +1211,30 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
case Action.EditEvent: {
// Quit early if we're trying to edit events in wrong rendering context
if (payload.timelineRenderingType !== this.state.timelineRenderingType) return;
if (payload.event && payload.event.getRoomId() !== this.state.roomId) {
// If the event is in a different room (e.g. all rooms search), we need to view that room first
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// If the event is in a different room (e.g. all rooms search), we need to view that room first
// If the event is in a different room (e.g. because the event to be edited is being displayed in the
// results of an all-rooms search), we need to view that room first.

dis.dispatch<ViewRoomPayload>({
action: Action.ViewRoom,
room_id: payload.event?.getRoomId(),
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
metricsTrigger: undefined,
deferred_action: payload,
});
return;
}

const editState = payload.event ? new EditorStateTransfer(payload.event) : undefined;
this.setState({ editState }, () => {
if (payload.event) {
this.messagePanel?.scrollToEventIfNeeded(payload.event.getId());
}
});
this.setState(
{
editState,
// Close any ongoing search as the RoomSearchView doesn't pass editState and thus won't render the edit composer
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
search: undefined,
},
() => {
if (payload.event) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel like maybe we should have an if (payload.event) at the start of the handler rather than lots of separate conditions on it, but whatever

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't my doing, its green because of an indent change performed by Prettier

this.messagePanel?.scrollToEventIfNeeded(payload.event.getId());
}
},
);
break;
}

Expand Down
Loading