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

Commit

Permalink
Fix joining public rooms without aliases in search dialog (#10437)
Browse files Browse the repository at this point in the history
Co-authored-by: Andy Balaam <andy.balaam@matrix.org>
  • Loading branch information
t3chguy and andybalaam authored Mar 27, 2023
1 parent 4552548 commit 1c039fc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/components/views/dialogs/spotlight/SpotlightDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ const SpotlightDialog: React.FC<IProps> = ({ 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 => {
Expand All @@ -518,6 +518,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
room_alias: room.roomAlias,
auto_join: room.autoJoin,
should_peek: room.shouldPeek,
via_servers: room.viaServers,
});
onFinished();
};
Expand Down Expand Up @@ -634,6 +635,7 @@ const SpotlightDialog: React.FC<IProps> = ({ 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",
Expand Down
37 changes: 36 additions & 1 deletion test/components/views/dialogs/SpotlightDialog-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
Expand Down Expand Up @@ -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 <b>shining</b> experience!",
world_readable: false,
Expand Down Expand Up @@ -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(<SpotlightDialog initialFilter={Filter.PublicRooms} onFinished={() => 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);
Expand Down

0 comments on commit 1c039fc

Please sign in to comment.