diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index cbfe8d0c2e..e57184604c 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -842,28 +842,13 @@ export class RoomView extends React.Component { }); break; case 'reply_to_event': - if (this.state.searchResults - && payload.event.getRoomId() === this.state.roomId - && !this.unmounted - && payload.context === TimelineRenderingType.Room) { + if (!this.unmounted && + this.state.searchResults && + payload.event.getRoomId() === this.state.roomId && + payload.context === TimelineRenderingType.Search + ) { this.onCancelSearchClick(); - } - break; - case 'quote': - if (this.state.searchResults) { - const roomId = payload.event.getRoomId(); - if (roomId === this.state.roomId) { - this.onCancelSearchClick(); - } - - setImmediate(() => { - dis.dispatch({ - action: Action.ViewRoom, - room_id: roomId, - deferred_action: payload, - metricsTrigger: "MessageSearch", - }); - }); + // we don't need to re-dispatch as RoomViewStore knows to persist with context=Search also } break; case 'MatrixActions.sync': diff --git a/src/stores/RoomViewStore.tsx b/src/stores/RoomViewStore.tsx index 66d045d11d..d6ee527f8b 100644 --- a/src/stores/RoomViewStore.tsx +++ b/src/stores/RoomViewStore.tsx @@ -198,10 +198,10 @@ class RoomViewStore extends Store { break; case 'reply_to_event': // 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) { + // this can happen when performing a search across all rooms. Persist the data from this event for + // both room and search timeline rendering types, search will get auto-closed by RoomView at this time. + if ([TimelineRenderingType.Room, TimelineRenderingType.Search].includes(payload.context)) { + if (payload.event?.getRoomId() !== this.state.roomId) { dis.dispatch({ action: Action.ViewRoom, room_id: payload.event.getRoomId(),