From e31042f1b1595088503945355b496632080b147f Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 11 Sep 2025 14:26:40 +0100 Subject: [PATCH] Fix history visibility when creating space rooms (#30745) * Fix history visibility when creating space rooms This line was here which made history visibility different for space rooms vs normal rooms, making history world readable for public rooms and shared from the point of invite (rather than joining) for any other rooms. I can't see any reason this makes sense, or why space rooms should have different history visibility defaults to other rooms. It wasn't commented. Let's just remove the line and make them consistent. * Fix import * Add some tests to asert that we don't randomly change the options that createRoom passes to the HS. --- src/createRoom.ts | 6 +--- test/unit-tests/createRoom-test.ts | 54 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/createRoom.ts b/src/createRoom.ts index 13dcb4e7af..c3bc1e6b1a 100644 --- a/src/createRoom.ts +++ b/src/createRoom.ts @@ -15,7 +15,7 @@ import { RoomCreateTypeField, RoomType, type ICreateRoomOpts, - HistoryVisibility, + type HistoryVisibility, JoinRule, Preset, RestrictedAllowType, @@ -224,10 +224,6 @@ export default async function createRoom(client: MatrixClient, opts: IOpts): Pro if (opts.parentSpace) { createOpts.initial_state.push(makeSpaceParentEvent(opts.parentSpace, true)); - if (!opts.historyVisibility) { - opts.historyVisibility = - createOpts.preset === Preset.PublicChat ? HistoryVisibility.WorldReadable : HistoryVisibility.Invited; - } if (opts.joinRule === JoinRule.Restricted) { createOpts.room_version = PreferredRoomVersions.RestrictedRooms; diff --git a/test/unit-tests/createRoom-test.ts b/test/unit-tests/createRoom-test.ts index d06e19cc83..06fb43cb4c 100644 --- a/test/unit-tests/createRoom-test.ts +++ b/test/unit-tests/createRoom-test.ts @@ -33,6 +33,60 @@ describe("createRoom", () => { afterEach(() => jest.clearAllMocks()); + it("creates a private room", async () => { + await createRoom(client, { createOpts: { preset: Preset.PrivateChat } }); + + expect(client.createRoom).toHaveBeenCalledWith({ + preset: "private_chat", + visibility: "private", + initial_state: [{ state_key: "", type: "m.room.guest_access", content: { guest_access: "can_join" } }], + }); + }); + + it("creates a private room in a space", async () => { + const roomId = await createRoom(client, { roomType: RoomType.Space }); + const parentSpace = client.getRoom(roomId!)!; + client.createRoom.mockClear(); + + await createRoom(client, { parentSpace, createOpts: { preset: Preset.PrivateChat } }); + + expect(client.createRoom).toHaveBeenCalledWith({ + preset: "private_chat", + visibility: "private", + initial_state: [ + { state_key: "", type: "m.room.guest_access", content: { guest_access: "can_join" } }, + { type: "m.space.parent", state_key: parentSpace.roomId, content: { canonical: true, via: [] } }, + ], + }); + }); + + it("creates a public room", async () => { + await createRoom(client, { createOpts: { preset: Preset.PublicChat } }); + + expect(client.createRoom).toHaveBeenCalledWith({ + preset: "public_chat", + visibility: "private", + initial_state: [{ state_key: "", type: "m.room.guest_access", content: { guest_access: "can_join" } }], + }); + }); + + it("creates a public room in a space", async () => { + const roomId = await createRoom(client, { roomType: RoomType.Space }); + const parentSpace = client.getRoom(roomId!)!; + client.createRoom.mockClear(); + + await createRoom(client, { parentSpace, createOpts: { preset: Preset.PublicChat } }); + + expect(client.createRoom).toHaveBeenCalledWith({ + preset: "public_chat", + visibility: "private", + initial_state: [ + { state_key: "", type: "m.room.guest_access", content: { guest_access: "can_join" } }, + { type: "m.space.parent", state_key: parentSpace.roomId, content: { canonical: true, via: [] } }, + ], + }); + }); + it("sets up Jitsi video rooms correctly", async () => { setupAsyncStoreWithClient(WidgetStore.instance, client); jest.spyOn(WidgetUtils, "waitForRoomWidget").mockResolvedValue();