Skip to content

Commit 2c19ea6

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

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

src/components/structures/SpaceRoomView.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ const SpaceSetupFirstRooms: React.FC<{
329329
return createRoom(space.client, {
330330
createOpts: {
331331
preset: isPublic ? Preset.PublicChat : Preset.PrivateChat,
332-
name,
333332
},
333+
name,
334334
spinner: false,
335335
encryption: false,
336336
andView: false,
@@ -423,7 +423,7 @@ const SpaceSetupPublicShare: React.FC<ISpaceSetupPublicShareProps> = ({
423423
<div className="mx_SpaceRoomView_publicShare">
424424
<h1>
425425
{_t("create_space|share_heading", {
426-
name: justCreatedOpts?.createOpts?.name || space.name,
426+
name: justCreatedOpts?.name || space.name,
427427
})}
428428
</h1>
429429
<div className="mx_SpaceRoomView_description">{_t("create_space|share_description")}</div>
@@ -449,7 +449,7 @@ const SpaceSetupPrivateScope: React.FC<{
449449
<h1>{_t("create_space|private_personal_heading")}</h1>
450450
<div className="mx_SpaceRoomView_description">
451451
{_t("create_space|private_personal_description", {
452-
name: justCreatedOpts?.createOpts?.name || space.name,
452+
name: justCreatedOpts?.name || space.name,
453453
})}
454454
</div>
455455

@@ -686,7 +686,7 @@ export default class SpaceRoomView extends React.PureComponent<IProps, IState> {
686686
<SpaceSetupFirstRooms
687687
space={this.props.space}
688688
title={_t("create_space|setup_rooms_community_heading", {
689-
spaceName: this.props.justCreatedOpts?.createOpts?.name || this.props.space.name,
689+
spaceName: this.props.justCreatedOpts?.name || this.props.space.name,
690690
})}
691691
description={
692692
<>

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)