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

Commit a491795

Browse files
authored
Fix RoomView ignoring alias lookup errors due to them not knowing the roomId (#11099)
1 parent 889318d commit a491795

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

src/components/structures/RoomView.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
519519
/**
520520
* Removes the Jitsi widget from the current user if
521521
* - Multiple Jitsi widgets have been added within {@link PREVENT_MULTIPLE_JITSI_WITHIN}
522-
* - The last (server timestamp) of these widgets is from the currrent user
522+
* - The last (server timestamp) of these widgets is from the current user
523523
* This solves the issue if some people decide to start a conference and click the call button at the same time.
524524
*/
525525
private doMaybeRemoveOwnJitsiWidget(): void {
@@ -592,7 +592,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
592592
return;
593593
}
594594

595-
if (!initial && this.state.roomId !== this.context.roomViewStore.getRoomId()) {
595+
const roomLoadError = this.context.roomViewStore.getRoomLoadError() ?? undefined;
596+
if (!initial && !roomLoadError && this.state.roomId !== this.context.roomViewStore.getRoomId()) {
596597
// RoomView explicitly does not support changing what room
597598
// is being viewed: instead it should just be re-mounted when
598599
// switching rooms. Therefore, if the room ID changes, we
@@ -614,7 +615,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
614615
roomId: roomId ?? undefined,
615616
roomAlias: this.context.roomViewStore.getRoomAlias() ?? undefined,
616617
roomLoading: this.context.roomViewStore.isRoomLoading(),
617-
roomLoadError: this.context.roomViewStore.getRoomLoadError() ?? undefined,
618+
roomLoadError,
618619
joining: this.context.roomViewStore.isJoining(),
619620
replyToEvent: this.context.roomViewStore.getQuotingEvent() ?? undefined,
620621
// we should only peek once we have a ready client

test/components/structures/RoomView-test.tsx

+20-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { mocked, MockedObject } from "jest-mock";
1919
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
2020
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
2121
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
22-
import { EventType, RoomStateEvent } from "matrix-js-sdk/src/matrix";
22+
import { EventType, MatrixError, RoomStateEvent } from "matrix-js-sdk/src/matrix";
2323
import { MEGOLM_ALGORITHM } from "matrix-js-sdk/src/crypto/olmlib";
2424
import { fireEvent, render, screen, RenderResult } from "@testing-library/react";
2525

@@ -34,6 +34,7 @@ import {
3434
filterConsole,
3535
mkRoomMemberJoinEvent,
3636
mkThirdPartyInviteEvent,
37+
emitPromise,
3738
} from "../../test-utils";
3839
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
3940
import { Action } from "../../../src/dispatcher/actions";
@@ -55,6 +56,7 @@ import VoipUserMapper from "../../../src/VoipUserMapper";
5556
import WidgetUtils from "../../../src/utils/WidgetUtils";
5657
import { WidgetType } from "../../../src/widgets/WidgetType";
5758
import WidgetStore from "../../../src/stores/WidgetStore";
59+
import { ViewRoomErrorPayload } from "../../../src/dispatcher/payloads/ViewRoomErrorPayload";
5860

5961
// Fake random strings to give a predictable snapshot for IDs
6062
jest.mock("matrix-js-sdk/src/randomstring", () => ({
@@ -138,8 +140,8 @@ describe("RoomView", () => {
138140
return roomView;
139141
};
140142

141-
const renderRoomView = async (): Promise<ReturnType<typeof render>> => {
142-
if (stores.roomViewStore.getRoomId() !== room.roomId) {
143+
const renderRoomView = async (switchRoom = true): Promise<ReturnType<typeof render>> => {
144+
if (switchRoom && stores.roomViewStore.getRoomId() !== room.roomId) {
143145
const switchedRoom = new Promise<void>((resolve) => {
144146
const subFn = () => {
145147
if (stores.roomViewStore.getRoomId()) {
@@ -498,4 +500,19 @@ describe("RoomView", () => {
498500
});
499501
});
500502
});
503+
504+
it("should show error view if failed to look up room alias", async () => {
505+
const { asFragment, findByText } = await renderRoomView(false);
506+
507+
defaultDispatcher.dispatch<ViewRoomErrorPayload>({
508+
action: Action.ViewRoomError,
509+
room_alias: "#addy:server",
510+
room_id: null,
511+
err: new MatrixError({ errcode: "M_NOT_FOUND" }),
512+
});
513+
await emitPromise(stores.roomViewStore, UPDATE_EVENT);
514+
515+
await findByText("Are you sure you're at the right place?");
516+
expect(asFragment()).toMatchSnapshot();
517+
});
501518
});

test/components/structures/__snapshots__/RoomView-test.tsx.snap

+29
Original file line numberDiff line numberDiff line change
@@ -809,3 +809,32 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t
809809
</div>
810810
</div>
811811
`;
812+
813+
exports[`RoomView should show error view if failed to look up room alias 1`] = `
814+
<DocumentFragment>
815+
<div
816+
class="mx_RoomView"
817+
>
818+
<div
819+
class="mx_RoomPreviewBar dark-panel mx_RoomPreviewBar_RoomNotFound mx_RoomPreviewBar_dialog"
820+
>
821+
<div
822+
class="mx_RoomPreviewBar_message"
823+
>
824+
<h3>
825+
#addy:server does not exist.
826+
</h3>
827+
<p>
828+
Are you sure you're at the right place?
829+
</p>
830+
</div>
831+
<div
832+
class="mx_RoomPreviewBar_actions"
833+
/>
834+
<div
835+
class="mx_RoomPreviewBar_footer"
836+
/>
837+
</div>
838+
</div>
839+
</DocumentFragment>
840+
`;

0 commit comments

Comments
 (0)