From ea8cbd5c93a393aa84590a2d717a43189ca5664e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 15 Jun 2023 13:10:41 +0100 Subject: [PATCH 1/3] Fix RoomView ignoring alias lookup errors due to them not having a roomId --- src/components/structures/RoomView.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 6e4dd7559f2..a5bdc24a43d 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -514,7 +514,7 @@ export class RoomView extends React.Component { /** * Removes the Jitsi widget from the current user if * - Multiple Jitsi widgets have been added within {@link PREVENT_MULTIPLE_JITSI_WITHIN} - * - The last (server timestamp) of these widgets is from the currrent user + * - The last (server timestamp) of these widgets is from the current user * This solves the issue if some people decide to start a conference and click the call button at the same time. */ private doMaybeRemoveOwnJitsiWidget(): void { @@ -587,7 +587,8 @@ export class RoomView extends React.Component { return; } - if (!initial && this.state.roomId !== this.context.roomViewStore.getRoomId()) { + const roomLoadError = this.context.roomViewStore.getRoomLoadError() ?? undefined; + if (!initial && !roomLoadError && this.state.roomId !== this.context.roomViewStore.getRoomId()) { // RoomView explicitly does not support changing what room // is being viewed: instead it should just be re-mounted when // switching rooms. Therefore, if the room ID changes, we @@ -609,7 +610,7 @@ export class RoomView extends React.Component { roomId: roomId ?? undefined, roomAlias: this.context.roomViewStore.getRoomAlias() ?? undefined, roomLoading: this.context.roomViewStore.isRoomLoading(), - roomLoadError: this.context.roomViewStore.getRoomLoadError() ?? undefined, + roomLoadError, joining: this.context.roomViewStore.isJoining(), replyToEvent: this.context.roomViewStore.getQuotingEvent() ?? undefined, // we should only peek once we have a ready client From 1708438cdad43dc1cbe8bfb0fc8283ca73d42fa6 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 19 Jun 2023 09:20:16 +0100 Subject: [PATCH 2/3] Add test --- test/components/structures/RoomView-test.tsx | 17 ++++++++-- .../__snapshots__/RoomView-test.tsx.snap | 34 +++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/test/components/structures/RoomView-test.tsx b/test/components/structures/RoomView-test.tsx index fadeb5c2c2e..7ad40b41224 100644 --- a/test/components/structures/RoomView-test.tsx +++ b/test/components/structures/RoomView-test.tsx @@ -55,6 +55,7 @@ import VoipUserMapper from "../../../src/VoipUserMapper"; import WidgetUtils from "../../../src/utils/WidgetUtils"; import { WidgetType } from "../../../src/widgets/WidgetType"; import WidgetStore from "../../../src/stores/WidgetStore"; +import { ViewRoomErrorPayload } from "../../../src/dispatcher/payloads/ViewRoomErrorPayload"; // Fake random strings to give a predictable snapshot for IDs jest.mock("matrix-js-sdk/src/randomstring", () => ({ @@ -138,8 +139,8 @@ describe("RoomView", () => { return roomView; }; - const renderRoomView = async (): Promise> => { - if (stores.roomViewStore.getRoomId() !== room.roomId) { + const renderRoomView = async (switchRoom = true): Promise> => { + if (switchRoom && stores.roomViewStore.getRoomId() !== room.roomId) { const switchedRoom = new Promise((resolve) => { const subFn = () => { if (stores.roomViewStore.getRoomId()) { @@ -497,4 +498,16 @@ describe("RoomView", () => { }); }); }); + + it("should show error view if failed to look up room alias", async () => { + const { asFragment } = await renderRoomView(); + + defaultDispatcher.dispatch({ + action: Action.ViewRoomError, + room_alias: "#addy:server", + room_id: null, + }); + + expect(asFragment()).toMatchSnapshot(); + }); }); diff --git a/test/components/structures/__snapshots__/RoomView-test.tsx.snap b/test/components/structures/__snapshots__/RoomView-test.tsx.snap index 251a3841b44..633e057c495 100644 --- a/test/components/structures/__snapshots__/RoomView-test.tsx.snap +++ b/test/components/structures/__snapshots__/RoomView-test.tsx.snap @@ -809,3 +809,37 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t `; + +exports[`RoomView should show error view if failed to look up room alias 1`] = ` + +
+
+
+

+ !0:example.org can't be previewed. Do you want to join it? +

+
+
+
+ Join the discussion +
+
+ +
+ +`; From 9cac581966f882a5d4ecab1b5ee08fa81172df05 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 19 Jun 2023 10:20:43 +0100 Subject: [PATCH 3/3] Fix test --- test/components/structures/RoomView-test.tsx | 8 ++++++-- .../__snapshots__/RoomView-test.tsx.snap | 17 ++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/test/components/structures/RoomView-test.tsx b/test/components/structures/RoomView-test.tsx index 7ad40b41224..945c543859d 100644 --- a/test/components/structures/RoomView-test.tsx +++ b/test/components/structures/RoomView-test.tsx @@ -19,7 +19,7 @@ import { mocked, MockedObject } from "jest-mock"; import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client"; import { Room, RoomEvent } from "matrix-js-sdk/src/models/room"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; -import { EventType, RoomStateEvent } from "matrix-js-sdk/src/matrix"; +import { EventType, MatrixError, RoomStateEvent } from "matrix-js-sdk/src/matrix"; import { MEGOLM_ALGORITHM } from "matrix-js-sdk/src/crypto/olmlib"; import { fireEvent, render, screen, RenderResult } from "@testing-library/react"; @@ -34,6 +34,7 @@ import { filterConsole, mkRoomMemberJoinEvent, mkThirdPartyInviteEvent, + emitPromise, } from "../../test-utils"; import { MatrixClientPeg } from "../../../src/MatrixClientPeg"; import { Action } from "../../../src/dispatcher/actions"; @@ -500,14 +501,17 @@ describe("RoomView", () => { }); it("should show error view if failed to look up room alias", async () => { - const { asFragment } = await renderRoomView(); + const { asFragment, findByText } = await renderRoomView(false); defaultDispatcher.dispatch({ action: Action.ViewRoomError, room_alias: "#addy:server", room_id: null, + err: new MatrixError({ errcode: "M_NOT_FOUND" }), }); + await emitPromise(stores.roomViewStore, UPDATE_EVENT); + await findByText("Are you sure you're at the right place?"); expect(asFragment()).toMatchSnapshot(); }); }); diff --git a/test/components/structures/__snapshots__/RoomView-test.tsx.snap b/test/components/structures/__snapshots__/RoomView-test.tsx.snap index 633e057c495..81ce09dc729 100644 --- a/test/components/structures/__snapshots__/RoomView-test.tsx.snap +++ b/test/components/structures/__snapshots__/RoomView-test.tsx.snap @@ -816,26 +816,21 @@ exports[`RoomView should show error view if failed to look up room alias 1`] = ` class="mx_RoomView" >

- !0:example.org can't be previewed. Do you want to join it? + #addy:server does not exist.

+

+ Are you sure you're at the right place? +

-
- Join the discussion -
-
+ />