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();