Skip to content

Commit 1c039fc

Browse files
t3chguyandybalaam
andauthored
Fix joining public rooms without aliases in search dialog (matrix-org#10437)
Co-authored-by: Andy Balaam <[email protected]>
1 parent 4552548 commit 1c039fc

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/components/views/dialogs/spotlight/SpotlightDialog.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
492492
}, [results, filter]);
493493

494494
const viewRoom = (
495-
room: { roomId: string; roomAlias?: string; autoJoin?: boolean; shouldPeek?: boolean },
495+
room: { roomId: string; roomAlias?: string; autoJoin?: boolean; shouldPeek?: boolean; viaServers?: string[] },
496496
persist = false,
497497
viaKeyboard = false,
498498
): void => {
@@ -518,6 +518,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
518518
room_alias: room.roomAlias,
519519
auto_join: room.autoJoin,
520520
should_peek: room.shouldPeek,
521+
via_servers: room.viaServers,
521522
});
522523
onFinished();
523524
};
@@ -634,6 +635,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
634635
roomId: publicRoom.room_id,
635636
autoJoin: !result.publicRoom.world_readable && !cli.isGuest(),
636637
shouldPeek: result.publicRoom.world_readable || cli.isGuest(),
638+
viaServers: [config.roomServer],
637639
},
638640
true,
639641
ev.type !== "click",

test/components/views/dialogs/SpotlightDialog-test.tsx

+36-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import { flushPromisesWithFakeTimers, mkRoom, stubClient } from "../../../test-u
2929
import { shouldShowFeedback } from "../../../../src/utils/Feedback";
3030
import SettingsStore from "../../../../src/settings/SettingsStore";
3131
import { SettingLevel } from "../../../../src/settings/SettingLevel";
32+
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
33+
import SdkConfig from "../../../../src/SdkConfig";
3234

3335
jest.useFakeTimers();
3436

@@ -40,6 +42,11 @@ jest.mock("../../../../src/utils/direct-messages", () => ({
4042
startDmOnFirstMessage: jest.fn(),
4143
}));
4244

45+
jest.mock("../../../../src/dispatcher/dispatcher", () => ({
46+
register: jest.fn(),
47+
dispatch: jest.fn(),
48+
}));
49+
4350
interface IUserChunkMember {
4451
user_id: string;
4552
display_name?: string;
@@ -122,7 +129,7 @@ describe("Spotlight Dialog", () => {
122129
};
123130

124131
const testPublicRoom: IPublicRoomsChunkRoom = {
125-
room_id: "@room247:matrix.org",
132+
room_id: "!room247:matrix.org",
126133
name: "Room #247",
127134
topic: "We hope you'll have a <b>shining</b> experience!",
128135
world_readable: false,
@@ -352,6 +359,34 @@ describe("Spotlight Dialog", () => {
352359
expect(startDmOnFirstMessage).toHaveBeenCalledWith(mockedClient, [new DirectoryMember(testPerson)]);
353360
});
354361

362+
it("should pass via of the server being explored when joining room from directory", async () => {
363+
SdkConfig.put({
364+
room_directory: {
365+
servers: ["example.tld"],
366+
},
367+
});
368+
localStorage.setItem("mx_last_room_directory_server", "example.tld");
369+
370+
render(<SpotlightDialog initialFilter={Filter.PublicRooms} onFinished={() => null} />);
371+
372+
jest.advanceTimersByTime(200);
373+
await flushPromisesWithFakeTimers();
374+
375+
const content = document.querySelector("#mx_SpotlightDialog_content")!;
376+
const options = content.querySelectorAll("div.mx_SpotlightDialog_option");
377+
expect(options.length).toBe(1);
378+
expect(options[0].innerHTML).toContain(testPublicRoom.name);
379+
380+
fireEvent.click(options[0]!);
381+
expect(defaultDispatcher.dispatch).toHaveBeenCalledWith(
382+
expect.objectContaining({
383+
action: "view_room",
384+
room_id: testPublicRoom.room_id,
385+
via_servers: ["example.tld"],
386+
}),
387+
);
388+
});
389+
355390
describe("Feedback prompt", () => {
356391
it("should show feedback prompt if feedback is enabled", async () => {
357392
mocked(shouldShowFeedback).mockReturnValue(true);

0 commit comments

Comments
 (0)