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

Commit

Permalink
Fix reply action in message context menu notif & file panels (#9895)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Jan 12, 2023
1 parent 098ba14 commit 0c30b57
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/stores/RoomViewStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,11 @@ export class RoomViewStore extends EventEmitter {
this.reset();
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. 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)) {
// Thread timeline view handles its own reply-to-state
if (TimelineRenderingType.Thread !== payload.context) {
// 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. 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 (payload.event && payload.event.getRoomId() !== this.state.roomId) {
this.dis.dispatch<ViewRoomPayload>({
action: Action.ViewRoom,
Expand Down
23 changes: 23 additions & 0 deletions test/stores/RoomViewStore-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

import { Room } from "matrix-js-sdk/src/matrix";
import { sleep } from "matrix-js-sdk/src/utils";

import { RoomViewStore } from "../../src/stores/RoomViewStore";
import { Action } from "../../src/dispatcher/actions";
Expand Down Expand Up @@ -245,6 +246,28 @@ describe("RoomViewStore", function () {
expect(roomViewStore.getRoomId()).toEqual(roomId2);
});

it("should ignore reply_to_event for Thread panels", async () => {
expect(roomViewStore.getQuotingEvent()).toBeFalsy();
const replyToEvent = {
getRoomId: () => roomId2,
};
dis.dispatch({ action: "reply_to_event", event: replyToEvent, context: TimelineRenderingType.Thread });
await sleep(100);
expect(roomViewStore.getQuotingEvent()).toBeFalsy();
});

it.each([TimelineRenderingType.Room, TimelineRenderingType.File, TimelineRenderingType.Notification])(
"Should respect reply_to_event for %s rendering context",
async (context) => {
const replyToEvent = {
getRoomId: () => roomId,
};
dis.dispatch({ action: "reply_to_event", event: replyToEvent, context });
await untilDispatch(Action.ViewRoom, dis);
expect(roomViewStore.getQuotingEvent()).toEqual(replyToEvent);
},
);

it("removes the roomId on ViewHomePage", async () => {
dis.dispatch({ action: Action.ViewRoom, room_id: roomId });
await untilDispatch(Action.ActiveRoomChanged, dis);
Expand Down

0 comments on commit 0c30b57

Please sign in to comment.