Skip to content

Commit fb4db94

Browse files
committed
feat: Move room name, avatar, and topic to IOpts.
1 parent 4a0e8d6 commit fb4db94

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

src/components/views/dialogs/CreateRoomDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
126126
const opts: IOpts = {};
127127
const createOpts: IOpts["createOpts"] = (opts.createOpts = {});
128128
opts.roomType = this.props.type;
129-
createOpts.name = this.state.name;
129+
opts.name = this.state.name;
130130

131131
if (this.state.joinRule === JoinRule.Public) {
132132
createOpts.visibility = Visibility.Public;
@@ -139,7 +139,7 @@ export default class CreateRoomDialog extends React.Component<IProps, IState> {
139139
}
140140

141141
if (this.state.topic) {
142-
createOpts.topic = this.state.topic;
142+
opts.topic = this.state.topic;
143143
}
144144
if (this.state.noFederate) {
145145
createOpts.creation_content = { "m.federate": false };

src/createRoom.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,19 @@ import { ElementCallEventType, ElementCallMemberEventType } from "./call-types";
4949

5050
export interface IOpts {
5151
dmUserId?: string;
52-
createOpts?: ICreateRoomOpts;
52+
/**
53+
* The name of the room to be created.
54+
*/
55+
name?: string;
56+
/**
57+
* The topic for the room.
58+
*/
59+
topic?: string;
60+
/**
61+
* Additional options to pass to the room creation API.
62+
* Note: "name", "topic", and "avatar" should be set via their respective properties in IOpts.
63+
*/
64+
createOpts?: Omit<ICreateRoomOpts, "name" | "topic" | "avatar">;
5365
spinner?: boolean;
5466
guestAccess?: boolean;
5567
encryption?: boolean;
@@ -251,6 +263,14 @@ export default async function createRoom(client: MatrixClient, opts: IOpts): Pro
251263
});
252264
}
253265

266+
if (opts.name) {
267+
createOpts.name = opts.name;
268+
}
269+
270+
if (opts.topic) {
271+
createOpts.topic = opts.topic;
272+
}
273+
254274
if (opts.avatar) {
255275
let url = opts.avatar;
256276
if (opts.avatar instanceof File) {

test/unit-tests/components/views/dialogs/CreateRoomDialog-test.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,8 @@ describe("<CreateRoomDialog />", () => {
198198
await flushPromises();
199199

200200
expect(onFinished).toHaveBeenCalledWith(true, {
201-
createOpts: {
202-
name: roomName,
203-
},
201+
createOpts: {},
202+
name: roomName,
204203
encryption: true,
205204
parentSpace: undefined,
206205
roomType: undefined,
@@ -259,9 +258,9 @@ describe("<CreateRoomDialog />", () => {
259258
await flushPromises();
260259
expect(onFinished).toHaveBeenCalledWith(true, {
261260
createOpts: {
262-
name: roomName,
263261
visibility: Visibility.Private,
264262
},
263+
name: roomName,
265264
encryption: true,
266265
joinRule: JoinRule.Knock,
267266
parentSpace: undefined,
@@ -277,9 +276,9 @@ describe("<CreateRoomDialog />", () => {
277276
await flushPromises();
278277
expect(onFinished).toHaveBeenCalledWith(true, {
279278
createOpts: {
280-
name: roomName,
281279
visibility: Visibility.Public,
282280
},
281+
name: roomName,
283282
encryption: true,
284283
joinRule: JoinRule.Knock,
285284
parentSpace: undefined,
@@ -349,11 +348,11 @@ describe("<CreateRoomDialog />", () => {
349348

350349
expect(onFinished).toHaveBeenCalledWith(true, {
351350
createOpts: {
352-
name: roomName,
353351
preset: Preset.PublicChat,
354352
room_alias_name: roomAlias,
355353
visibility: Visibility.Public,
356354
},
355+
name: roomName,
357356
guestAccess: false,
358357
parentSpace: undefined,
359358
roomType: undefined,

0 commit comments

Comments
 (0)