Fix RoomView ignoring alias lookup errors due to them not knowing the roomId (#11099)

t3chguy/dedup-icons-17oct
Michael Telatynski 2023-06-19 17:08:16 +01:00 committed by GitHub
parent 889318d3a2
commit a491795aa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 6 deletions

View File

@ -519,7 +519,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
/** /**
* Removes the Jitsi widget from the current user if * Removes the Jitsi widget from the current user if
* - Multiple Jitsi widgets have been added within {@link PREVENT_MULTIPLE_JITSI_WITHIN} * - 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. * This solves the issue if some people decide to start a conference and click the call button at the same time.
*/ */
private doMaybeRemoveOwnJitsiWidget(): void { private doMaybeRemoveOwnJitsiWidget(): void {
@ -592,7 +592,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
return; 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 // RoomView explicitly does not support changing what room
// is being viewed: instead it should just be re-mounted when // is being viewed: instead it should just be re-mounted when
// switching rooms. Therefore, if the room ID changes, we // switching rooms. Therefore, if the room ID changes, we
@ -614,7 +615,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
roomId: roomId ?? undefined, roomId: roomId ?? undefined,
roomAlias: this.context.roomViewStore.getRoomAlias() ?? undefined, roomAlias: this.context.roomViewStore.getRoomAlias() ?? undefined,
roomLoading: this.context.roomViewStore.isRoomLoading(), roomLoading: this.context.roomViewStore.isRoomLoading(),
roomLoadError: this.context.roomViewStore.getRoomLoadError() ?? undefined, roomLoadError,
joining: this.context.roomViewStore.isJoining(), joining: this.context.roomViewStore.isJoining(),
replyToEvent: this.context.roomViewStore.getQuotingEvent() ?? undefined, replyToEvent: this.context.roomViewStore.getQuotingEvent() ?? undefined,
// we should only peek once we have a ready client // we should only peek once we have a ready client

View File

@ -19,7 +19,7 @@ import { mocked, MockedObject } from "jest-mock";
import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client"; import { ClientEvent, MatrixClient } from "matrix-js-sdk/src/client";
import { Room, RoomEvent } from "matrix-js-sdk/src/models/room"; import { Room, RoomEvent } from "matrix-js-sdk/src/models/room";
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; 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 { MEGOLM_ALGORITHM } from "matrix-js-sdk/src/crypto/olmlib";
import { fireEvent, render, screen, RenderResult } from "@testing-library/react"; import { fireEvent, render, screen, RenderResult } from "@testing-library/react";
@ -34,6 +34,7 @@ import {
filterConsole, filterConsole,
mkRoomMemberJoinEvent, mkRoomMemberJoinEvent,
mkThirdPartyInviteEvent, mkThirdPartyInviteEvent,
emitPromise,
} from "../../test-utils"; } from "../../test-utils";
import { MatrixClientPeg } from "../../../src/MatrixClientPeg"; import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
import { Action } from "../../../src/dispatcher/actions"; import { Action } from "../../../src/dispatcher/actions";
@ -55,6 +56,7 @@ import VoipUserMapper from "../../../src/VoipUserMapper";
import WidgetUtils from "../../../src/utils/WidgetUtils"; import WidgetUtils from "../../../src/utils/WidgetUtils";
import { WidgetType } from "../../../src/widgets/WidgetType"; import { WidgetType } from "../../../src/widgets/WidgetType";
import WidgetStore from "../../../src/stores/WidgetStore"; import WidgetStore from "../../../src/stores/WidgetStore";
import { ViewRoomErrorPayload } from "../../../src/dispatcher/payloads/ViewRoomErrorPayload";
// Fake random strings to give a predictable snapshot for IDs // Fake random strings to give a predictable snapshot for IDs
jest.mock("matrix-js-sdk/src/randomstring", () => ({ jest.mock("matrix-js-sdk/src/randomstring", () => ({
@ -138,8 +140,8 @@ describe("RoomView", () => {
return roomView; return roomView;
}; };
const renderRoomView = async (): Promise<ReturnType<typeof render>> => { const renderRoomView = async (switchRoom = true): Promise<ReturnType<typeof render>> => {
if (stores.roomViewStore.getRoomId() !== room.roomId) { if (switchRoom && stores.roomViewStore.getRoomId() !== room.roomId) {
const switchedRoom = new Promise<void>((resolve) => { const switchedRoom = new Promise<void>((resolve) => {
const subFn = () => { const subFn = () => {
if (stores.roomViewStore.getRoomId()) { if (stores.roomViewStore.getRoomId()) {
@ -498,4 +500,19 @@ describe("RoomView", () => {
}); });
}); });
}); });
it("should show error view if failed to look up room alias", async () => {
const { asFragment, findByText } = await renderRoomView(false);
defaultDispatcher.dispatch<ViewRoomErrorPayload>({
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();
});
}); });

View File

@ -809,3 +809,32 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t
</div> </div>
</div> </div>
`; `;
exports[`RoomView should show error view if failed to look up room alias 1`] = `
<DocumentFragment>
<div
class="mx_RoomView"
>
<div
class="mx_RoomPreviewBar dark-panel mx_RoomPreviewBar_RoomNotFound mx_RoomPreviewBar_dialog"
>
<div
class="mx_RoomPreviewBar_message"
>
<h3>
#addy:server does not exist.
</h3>
<p>
Are you sure you're at the right place?
</p>
</div>
<div
class="mx_RoomPreviewBar_actions"
/>
<div
class="mx_RoomPreviewBar_footer"
/>
</div>
</div>
</DocumentFragment>
`;