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

Fix joining public rooms without aliases in search dialog #10437

Merged
merged 3 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 directrory", async () => {
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
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