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.
This commit is contained in:
David Baker
2025-09-11 14:26:40 +01:00
committed by GitHub
parent 1c1f1435be
commit e31042f1b1
2 changed files with 55 additions and 5 deletions

View File

@@ -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;

View File

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