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

Commit aadb463

Browse files
authored
Fix thread navigation in timeline (#12412)
* Remove thread dispatch action * Add comment * Add e2e test
1 parent 77dfc1a commit aadb463

File tree

2 files changed

+70
-10
lines changed

2 files changed

+70
-10
lines changed

playwright/e2e/threads/threads.spec.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,4 +447,72 @@ test.describe("Threads", () => {
447447
await expect(locator.locator(".mx_EventTile").first().getByText("Hello Mr. Bot")).toBeAttached();
448448
await expect(locator.locator(".mx_EventTile").last().getByText("Hello Mr. User")).toBeAttached();
449449
});
450+
451+
test("navigate through right panel", async ({ page, app, user }) => {
452+
// Create room
453+
const roomId = await app.client.createRoom({});
454+
await page.goto("/#/room/" + roomId);
455+
456+
/**
457+
* Send a message in the main timeline
458+
* @param message
459+
*/
460+
const sendMessage = async (message: string) => {
461+
const messageComposer = page.getByRole("region", { name: "Message composer" });
462+
const textbox = messageComposer.getByRole("textbox", { name: "Send a message…" });
463+
await textbox.fill(message);
464+
await textbox.press("Enter");
465+
};
466+
467+
/**
468+
* Create a thread from the rootMessage and send a message in the thread
469+
* @param rootMessage
470+
* @param threadMessage
471+
*/
472+
const createThread = async (rootMessage: string, threadMessage: string) => {
473+
// First create a thread
474+
const roomViewBody = page.locator(".mx_RoomView_body");
475+
const messageTile = roomViewBody
476+
.locator(".mx_EventTile[data-scroll-tokens]")
477+
.filter({ hasText: rootMessage });
478+
await messageTile.hover();
479+
await messageTile.getByRole("button", { name: "Reply in thread" }).click();
480+
await expect(page.locator(".mx_ThreadView_timelinePanelWrapper")).toHaveCount(1);
481+
482+
// Send a message in the thread
483+
const threadPanel = page.locator(".mx_ThreadPanel");
484+
const textbox = threadPanel.getByRole("textbox", { name: "Send a message…" });
485+
await textbox.fill(threadMessage);
486+
await textbox.press("Enter");
487+
await expect(threadPanel.locator(".mx_EventTile_last").getByText(threadMessage)).toBeVisible();
488+
// Close thread
489+
await threadPanel.getByRole("button", { name: "Close" }).click();
490+
};
491+
492+
await sendMessage("Hello Mr. Bot");
493+
await sendMessage("Hello again Mr. Bot");
494+
await createThread("Hello Mr. Bot", "Hello Mr. User in a thread");
495+
await createThread("Hello again Mr. Bot", "Hello again Mr. User in a thread");
496+
497+
// Open thread panel
498+
await page.getByRole("button", { name: "Threads" }).click();
499+
const threadPanel = page.locator(".mx_ThreadPanel");
500+
await expect(
501+
threadPanel.locator(".mx_EventTile_last").getByText("Hello again Mr. User in a thread"),
502+
).toBeVisible();
503+
504+
// Open threads list
505+
await threadPanel.getByRole("button", { name: "Threads" }).click();
506+
const rightPanel = page.locator(".mx_RightPanel");
507+
// Check that the threads are listed
508+
await expect(rightPanel.locator(".mx_EventTile").getByText("Hello Mr. User in a thread")).toBeVisible();
509+
await expect(rightPanel.locator(".mx_EventTile").getByText("Hello again Mr. User in a thread")).toBeVisible();
510+
511+
// Open the first thread
512+
await rightPanel.locator(".mx_EventTile").getByText("Hello Mr. User in a thread").click();
513+
await expect(rightPanel.locator(".mx_EventTile").getByText("Hello Mr. User in a thread")).toBeVisible();
514+
await expect(
515+
rightPanel.locator(".mx_EventTile").getByText("Hello again Mr. User in a thread"),
516+
).not.toBeVisible();
517+
});
450518
});

src/components/structures/RoomView.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
707707
newState.initialEventPixelOffset = undefined;
708708

709709
const thread = initialEvent?.getThread();
710+
// Handle the use case of a link to a thread message
711+
// ie: #/room/roomId/eventId (eventId of a thread message)
710712
if (thread?.rootEvent && !initialEvent?.isThreadRoot) {
711713
dis.dispatch<ShowThreadPayload>({
712714
action: Action.ShowThread,
@@ -719,16 +721,6 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
719721
newState.initialEventId = initialEventId;
720722
newState.isInitialEventHighlighted = this.context.roomViewStore.isInitialEventHighlighted();
721723
newState.initialEventScrollIntoView = this.context.roomViewStore.initialEventScrollIntoView();
722-
723-
if (thread?.rootEvent && initialEvent?.isThreadRoot) {
724-
dis.dispatch<ShowThreadPayload>({
725-
action: Action.ShowThread,
726-
rootEvent: thread.rootEvent,
727-
initialEvent,
728-
highlighted: this.context.roomViewStore.isInitialEventHighlighted(),
729-
scroll_into_view: this.context.roomViewStore.initialEventScrollIntoView(),
730-
});
731-
}
732724
}
733725
}
734726

0 commit comments

Comments
 (0)