Fix joining public rooms without aliases in search dialog (#10437)

Co-authored-by: Andy Balaam <andy.balaam@matrix.org>
This commit is contained in:
Michael Telatynski 2023-03-27 08:39:34 +01:00 committed by GitHub
parent 45525480ef
commit 1c039fcd38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 2 deletions

View file

@ -492,7 +492,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
}, [results, filter]); }, [results, filter]);
const viewRoom = ( const viewRoom = (
room: { roomId: string; roomAlias?: string; autoJoin?: boolean; shouldPeek?: boolean }, room: { roomId: string; roomAlias?: string; autoJoin?: boolean; shouldPeek?: boolean; viaServers?: string[] },
persist = false, persist = false,
viaKeyboard = false, viaKeyboard = false,
): void => { ): void => {
@ -518,6 +518,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
room_alias: room.roomAlias, room_alias: room.roomAlias,
auto_join: room.autoJoin, auto_join: room.autoJoin,
should_peek: room.shouldPeek, should_peek: room.shouldPeek,
via_servers: room.viaServers,
}); });
onFinished(); onFinished();
}; };
@ -634,6 +635,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
roomId: publicRoom.room_id, roomId: publicRoom.room_id,
autoJoin: !result.publicRoom.world_readable && !cli.isGuest(), autoJoin: !result.publicRoom.world_readable && !cli.isGuest(),
shouldPeek: result.publicRoom.world_readable || cli.isGuest(), shouldPeek: result.publicRoom.world_readable || cli.isGuest(),
viaServers: [config.roomServer],
}, },
true, true,
ev.type !== "click", ev.type !== "click",

View file

@ -29,6 +29,8 @@ import { flushPromisesWithFakeTimers, mkRoom, stubClient } from "../../../test-u
import { shouldShowFeedback } from "../../../../src/utils/Feedback"; import { shouldShowFeedback } from "../../../../src/utils/Feedback";
import SettingsStore from "../../../../src/settings/SettingsStore"; import SettingsStore from "../../../../src/settings/SettingsStore";
import { SettingLevel } from "../../../../src/settings/SettingLevel"; import { SettingLevel } from "../../../../src/settings/SettingLevel";
import defaultDispatcher from "../../../../src/dispatcher/dispatcher";
import SdkConfig from "../../../../src/SdkConfig";
jest.useFakeTimers(); jest.useFakeTimers();
@ -40,6 +42,11 @@ jest.mock("../../../../src/utils/direct-messages", () => ({
startDmOnFirstMessage: jest.fn(), startDmOnFirstMessage: jest.fn(),
})); }));
jest.mock("../../../../src/dispatcher/dispatcher", () => ({
register: jest.fn(),
dispatch: jest.fn(),
}));
interface IUserChunkMember { interface IUserChunkMember {
user_id: string; user_id: string;
display_name?: string; display_name?: string;
@ -122,7 +129,7 @@ describe("Spotlight Dialog", () => {
}; };
const testPublicRoom: IPublicRoomsChunkRoom = { const testPublicRoom: IPublicRoomsChunkRoom = {
room_id: "@room247:matrix.org", room_id: "!room247:matrix.org",
name: "Room #247", name: "Room #247",
topic: "We hope you'll have a <b>shining</b> experience!", topic: "We hope you'll have a <b>shining</b> experience!",
world_readable: false, world_readable: false,
@ -352,6 +359,34 @@ describe("Spotlight Dialog", () => {
expect(startDmOnFirstMessage).toHaveBeenCalledWith(mockedClient, [new DirectoryMember(testPerson)]); 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", () => { describe("Feedback prompt", () => {
it("should show feedback prompt if feedback is enabled", async () => { it("should show feedback prompt if feedback is enabled", async () => {
mocked(shouldShowFeedback).mockReturnValue(true); mocked(shouldShowFeedback).mockReturnValue(true);