From 1c039fcd3880ef4fefa58812d375104d2d70fe6c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 27 Mar 2023 08:39:34 +0100 Subject: [PATCH] Fix joining public rooms without aliases in search dialog (#10437) Co-authored-by: Andy Balaam --- .../dialogs/spotlight/SpotlightDialog.tsx | 4 +- .../views/dialogs/SpotlightDialog-test.tsx | 37 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx index 37c2bace25..ba1e0098f6 100644 --- a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx +++ b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx @@ -492,7 +492,7 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n }, [results, filter]); const viewRoom = ( - room: { roomId: string; roomAlias?: string; autoJoin?: boolean; shouldPeek?: boolean }, + room: { roomId: string; roomAlias?: string; autoJoin?: boolean; shouldPeek?: boolean; viaServers?: string[] }, persist = false, viaKeyboard = false, ): void => { @@ -518,6 +518,7 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n room_alias: room.roomAlias, auto_join: room.autoJoin, should_peek: room.shouldPeek, + via_servers: room.viaServers, }); onFinished(); }; @@ -634,6 +635,7 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n roomId: publicRoom.room_id, autoJoin: !result.publicRoom.world_readable && !cli.isGuest(), shouldPeek: result.publicRoom.world_readable || cli.isGuest(), + viaServers: [config.roomServer], }, true, ev.type !== "click", diff --git a/test/components/views/dialogs/SpotlightDialog-test.tsx b/test/components/views/dialogs/SpotlightDialog-test.tsx index f6fa68bde0..8e15ed390d 100644 --- a/test/components/views/dialogs/SpotlightDialog-test.tsx +++ b/test/components/views/dialogs/SpotlightDialog-test.tsx @@ -29,6 +29,8 @@ import { flushPromisesWithFakeTimers, mkRoom, stubClient } from "../../../test-u import { shouldShowFeedback } from "../../../../src/utils/Feedback"; import SettingsStore from "../../../../src/settings/SettingsStore"; import { SettingLevel } from "../../../../src/settings/SettingLevel"; +import defaultDispatcher from "../../../../src/dispatcher/dispatcher"; +import SdkConfig from "../../../../src/SdkConfig"; jest.useFakeTimers(); @@ -40,6 +42,11 @@ jest.mock("../../../../src/utils/direct-messages", () => ({ startDmOnFirstMessage: jest.fn(), })); +jest.mock("../../../../src/dispatcher/dispatcher", () => ({ + register: jest.fn(), + dispatch: jest.fn(), +})); + interface IUserChunkMember { user_id: string; display_name?: string; @@ -122,7 +129,7 @@ describe("Spotlight Dialog", () => { }; const testPublicRoom: IPublicRoomsChunkRoom = { - room_id: "@room247:matrix.org", + room_id: "!room247:matrix.org", name: "Room #247", topic: "We hope you'll have a shining experience!", world_readable: false, @@ -352,6 +359,34 @@ describe("Spotlight Dialog", () => { expect(startDmOnFirstMessage).toHaveBeenCalledWith(mockedClient, [new DirectoryMember(testPerson)]); }); + it("should pass via of the server being explored when joining room from directory", async () => { + SdkConfig.put({ + room_directory: { + servers: ["example.tld"], + }, + }); + localStorage.setItem("mx_last_room_directory_server", "example.tld"); + + render( null} />); + + jest.advanceTimersByTime(200); + await flushPromisesWithFakeTimers(); + + const content = document.querySelector("#mx_SpotlightDialog_content")!; + const options = content.querySelectorAll("div.mx_SpotlightDialog_option"); + expect(options.length).toBe(1); + expect(options[0].innerHTML).toContain(testPublicRoom.name); + + fireEvent.click(options[0]!); + expect(defaultDispatcher.dispatch).toHaveBeenCalledWith( + expect.objectContaining({ + action: "view_room", + room_id: testPublicRoom.room_id, + via_servers: ["example.tld"], + }), + ); + }); + describe("Feedback prompt", () => { it("should show feedback prompt if feedback is enabled", async () => { mocked(shouldShowFeedback).mockReturnValue(true);