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

Commit 3acd648

Browse files
authored
Fix timeline position when moving to a room and coming back (#12055)
* Force `initialEventId` in `RoomView` * Remove Force `initialEventId` in `RoomView` * Add e2e tests to verify we memorize the timeline position * Fill `viewRoomOpts` in `viewRoom` * Reset jest mock in sliding sync test * Add comments
1 parent 537b4a1 commit 3acd648

File tree

6 files changed

+52
-34
lines changed

6 files changed

+52
-34
lines changed

playwright/e2e/room/room.spec.ts

+39
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,43 @@ test.describe("Room Directory", () => {
6060
// confirm the room was loaded
6161
await expect(page.getByText("Charlie joined the room")).toBeVisible();
6262
});
63+
64+
test("should memorize the timeline position when switch Room A -> Room B -> Room A", async ({
65+
page,
66+
app,
67+
user,
68+
}) => {
69+
// Create the two rooms
70+
const roomAId = await app.client.createRoom({ name: "Room A" });
71+
const roomBId = await app.client.createRoom({ name: "Room B" });
72+
// Display Room A
73+
await app.viewRoomById(roomAId);
74+
75+
// Send the first message and get the event ID
76+
const { event_id: eventId } = await app.client.sendMessage(roomAId, { body: "test0", msgtype: "m.text" });
77+
// Send 49 more messages
78+
for (let i = 1; i < 50; i++) {
79+
await app.client.sendMessage(roomAId, { body: `test${i}`, msgtype: "m.text" });
80+
}
81+
82+
// Wait for all the messages to be displayed
83+
await expect(
84+
page.locator(".mx_EventTile_last .mx_MTextBody .mx_EventTile_body").getByText("test49"),
85+
).toBeVisible();
86+
87+
// Display the first message
88+
await page.goto(`/#/room/${roomAId}/${eventId}`);
89+
90+
// Wait for the first message to be displayed
91+
await expect(page.locator(".mx_MTextBody .mx_EventTile_body").getByText("test0")).toBeInViewport();
92+
93+
// Display Room B
94+
await app.viewRoomById(roomBId);
95+
// Display Room A
96+
await app.viewRoomById(roomAId);
97+
98+
// The timeline should display the first message
99+
// The previous position before switching to Room B should be remembered
100+
await expect(page.locator(".mx_MTextBody .mx_EventTile_body").getByText("test0")).toBeInViewport();
101+
});
63102
});

src/components/structures/RoomView.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -1407,8 +1407,6 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
14071407
tombstone: this.getRoomTombstone(room),
14081408
liveTimeline: room.getLiveTimeline(),
14091409
});
1410-
1411-
dis.dispatch<ActionPayload>({ action: Action.RoomLoaded });
14121410
};
14131411

14141412
private onRoomTimelineReset = (room?: Room): void => {

src/dispatcher/actions.ts

-5
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,6 @@ export enum Action {
372372
*/
373373
OpenSpotlight = "open_spotlight",
374374

375-
/**
376-
* Fired when the room loaded.
377-
*/
378-
RoomLoaded = "room_loaded",
379-
380375
/**
381376
* Opens right panel with 3pid invite information
382377
*/

src/stores/RoomViewStore.tsx

+5-15
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,6 @@ export class RoomViewStore extends EventEmitter {
375375
this.cancelAskToJoin(payload as CancelAskToJoinPayload);
376376
break;
377377
}
378-
case Action.RoomLoaded: {
379-
this.setViewRoomOpts();
380-
break;
381-
}
382378
}
383379
}
384380

@@ -443,6 +439,10 @@ export class RoomViewStore extends EventEmitter {
443439
return;
444440
}
445441

442+
const viewRoomOpts: ViewRoomOpts = { buttons: [] };
443+
// Allow modules to update the list of buttons for the room by updating `viewRoomOpts`.
444+
ModuleRunner.instance.invoke(RoomViewLifecycle.ViewRoom, viewRoomOpts, this.getRoomId());
445+
446446
const newState: Partial<State> = {
447447
roomId: payload.room_id,
448448
roomAlias: payload.room_alias ?? null,
@@ -464,6 +464,7 @@ export class RoomViewStore extends EventEmitter {
464464
(payload.room_id === this.state.roomId
465465
? this.state.viewingCall
466466
: CallStore.instance.getActiveCall(payload.room_id) !== null),
467+
viewRoomOpts,
467468
};
468469

469470
// Allow being given an event to be replied to when switching rooms but sanity check its for this room
@@ -823,15 +824,4 @@ export class RoomViewStore extends EventEmitter {
823824
public getViewRoomOpts(): ViewRoomOpts {
824825
return this.state.viewRoomOpts;
825826
}
826-
827-
/**
828-
* Invokes the view room lifecycle to set the view room options.
829-
*
830-
* @returns {void}
831-
*/
832-
private setViewRoomOpts(): void {
833-
const viewRoomOpts: ViewRoomOpts = { buttons: [] };
834-
ModuleRunner.instance.invoke(RoomViewLifecycle.ViewRoom, viewRoomOpts, this.getRoomId());
835-
this.setState({ viewRoomOpts });
836-
}
837827
}

test/components/structures/RoomView-test.tsx

-6
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,4 @@ describe("RoomView", () => {
585585
expect(dis.dispatch).toHaveBeenCalledWith({ action: "cancel_ask_to_join", roomId: room.roomId });
586586
});
587587
});
588-
589-
it("fires Action.RoomLoaded", async () => {
590-
jest.spyOn(dis, "dispatch");
591-
await mountRoomView();
592-
expect(dis.dispatch).toHaveBeenCalledWith({ action: Action.RoomLoaded });
593-
});
594588
});

test/stores/RoomViewStore-test.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,6 @@ describe("RoomViewStore", function () {
134134
await untilDispatch(Action.CancelAskToJoin, dis);
135135
};
136136

137-
const dispatchRoomLoaded = async () => {
138-
dis.dispatch({ action: Action.RoomLoaded });
139-
await untilDispatch(Action.RoomLoaded, dis);
140-
};
141-
142137
let roomViewStore: RoomViewStore;
143138
let slidingSyncManager: SlidingSyncManager;
144139
let dis: MatrixDispatcher;
@@ -425,6 +420,10 @@ describe("RoomViewStore", function () {
425420
});
426421
});
427422

423+
afterEach(() => {
424+
jest.spyOn(SettingsStore, "getValue").mockReset();
425+
});
426+
428427
it("subscribes to the room", async () => {
429428
const setRoomVisible = jest
430429
.spyOn(slidingSyncManager, "setRoomVisible")
@@ -598,7 +597,10 @@ describe("RoomViewStore", function () {
598597
opts.buttons = buttons;
599598
}
600599
});
601-
await dispatchRoomLoaded();
600+
601+
dis.dispatch({ action: Action.ViewRoom, room_id: roomId });
602+
await untilDispatch(Action.ViewRoom, dis);
603+
602604
expect(roomViewStore.getViewRoomOpts()).toEqual({ buttons });
603605
});
604606
});

0 commit comments

Comments
 (0)