From 190f2bc21874050c4d33e40d4907e6b96b1d7a68 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 23 Mar 2023 16:43:38 +0000 Subject: [PATCH 1/3] Fix joining public rooms without aliases in search dialog --- src/components/views/dialogs/spotlight/SpotlightDialog.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx index 6e2b113ee6b..d0084ad5aa6 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", From ad8056aa0017a9c2772c80428bdf596c7e163b93 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 24 Mar 2023 09:58:38 +0000 Subject: [PATCH 2/3] Add test --- .../views/dialogs/SpotlightDialog-test.tsx | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/test/components/views/dialogs/SpotlightDialog-test.tsx b/test/components/views/dialogs/SpotlightDialog-test.tsx index f6fa68bde0e..d2deae144ee 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 directrory", 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); From 2312ace6f6e3642e2845a79ff08e2d3e809e3c7a Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 27 Mar 2023 08:18:46 +0100 Subject: [PATCH 3/3] Update test/components/views/dialogs/SpotlightDialog-test.tsx Co-authored-by: Andy Balaam --- test/components/views/dialogs/SpotlightDialog-test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/components/views/dialogs/SpotlightDialog-test.tsx b/test/components/views/dialogs/SpotlightDialog-test.tsx index d2deae144ee..8e15ed390de 100644 --- a/test/components/views/dialogs/SpotlightDialog-test.tsx +++ b/test/components/views/dialogs/SpotlightDialog-test.tsx @@ -359,7 +359,7 @@ describe("Spotlight Dialog", () => { expect(startDmOnFirstMessage).toHaveBeenCalledWith(mockedClient, [new DirectoryMember(testPerson)]); }); - it("should pass via of the server being explored when joining room from directrory", async () => { + it("should pass via of the server being explored when joining room from directory", async () => { SdkConfig.put({ room_directory: { servers: ["example.tld"],