Skip to content

Commit bbe5b46

Browse files
dbkrHalf-Shot
authored andcommitted
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.
1 parent 798327c commit bbe5b46

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

src/createRoom.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
RoomCreateTypeField,
1616
RoomType,
1717
type ICreateRoomOpts,
18-
HistoryVisibility,
18+
type HistoryVisibility,
1919
JoinRule,
2020
Preset,
2121
RestrictedAllowType,
@@ -224,10 +224,6 @@ export default async function createRoom(client: MatrixClient, opts: IOpts): Pro
224224

225225
if (opts.parentSpace) {
226226
createOpts.initial_state.push(makeSpaceParentEvent(opts.parentSpace, true));
227-
if (!opts.historyVisibility) {
228-
opts.historyVisibility =
229-
createOpts.preset === Preset.PublicChat ? HistoryVisibility.WorldReadable : HistoryVisibility.Invited;
230-
}
231227

232228
if (opts.joinRule === JoinRule.Restricted) {
233229
createOpts.room_version = PreferredRoomVersions.RestrictedRooms;

test/unit-tests/createRoom-test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,60 @@ describe("createRoom", () => {
3333

3434
afterEach(() => jest.clearAllMocks());
3535

36+
it("creates a private room", async () => {
37+
await createRoom(client, { createOpts: { preset: Preset.PrivateChat } });
38+
39+
expect(client.createRoom).toHaveBeenCalledWith({
40+
preset: "private_chat",
41+
visibility: "private",
42+
initial_state: [{ state_key: "", type: "m.room.guest_access", content: { guest_access: "can_join" } }],
43+
});
44+
});
45+
46+
it("creates a private room in a space", async () => {
47+
const roomId = await createRoom(client, { roomType: RoomType.Space });
48+
const parentSpace = client.getRoom(roomId!)!;
49+
client.createRoom.mockClear();
50+
51+
await createRoom(client, { parentSpace, createOpts: { preset: Preset.PrivateChat } });
52+
53+
expect(client.createRoom).toHaveBeenCalledWith({
54+
preset: "private_chat",
55+
visibility: "private",
56+
initial_state: [
57+
{ state_key: "", type: "m.room.guest_access", content: { guest_access: "can_join" } },
58+
{ type: "m.space.parent", state_key: parentSpace.roomId, content: { canonical: true, via: [] } },
59+
],
60+
});
61+
});
62+
63+
it("creates a public room", async () => {
64+
await createRoom(client, { createOpts: { preset: Preset.PublicChat } });
65+
66+
expect(client.createRoom).toHaveBeenCalledWith({
67+
preset: "public_chat",
68+
visibility: "private",
69+
initial_state: [{ state_key: "", type: "m.room.guest_access", content: { guest_access: "can_join" } }],
70+
});
71+
});
72+
73+
it("creates a public room in a space", async () => {
74+
const roomId = await createRoom(client, { roomType: RoomType.Space });
75+
const parentSpace = client.getRoom(roomId!)!;
76+
client.createRoom.mockClear();
77+
78+
await createRoom(client, { parentSpace, createOpts: { preset: Preset.PublicChat } });
79+
80+
expect(client.createRoom).toHaveBeenCalledWith({
81+
preset: "public_chat",
82+
visibility: "private",
83+
initial_state: [
84+
{ state_key: "", type: "m.room.guest_access", content: { guest_access: "can_join" } },
85+
{ type: "m.space.parent", state_key: parentSpace.roomId, content: { canonical: true, via: [] } },
86+
],
87+
});
88+
});
89+
3690
it("sets up Jitsi video rooms correctly", async () => {
3791
setupAsyncStoreWithClient(WidgetStore.instance, client);
3892
jest.spyOn(WidgetUtils, "waitForRoomWidget").mockResolvedValue();

0 commit comments

Comments
 (0)