From 26fa2a5d601816963771c18001db5c84c7153c28 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 7 Feb 2022 18:58:43 +0100 Subject: [PATCH] add option --- src/matrix/Session.js | 8 ++++++-- src/matrix/room/create.ts | 16 +++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 02635855..13901e6c 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -592,13 +592,17 @@ export class Session { return this._roomsBeingCreated; } - createRoom(type, isEncrypted, explicitName, topic, invites, log = undefined) { + createRoom(type, isEncrypted, explicitName, topic, invites, options = undefined, log = undefined) { return this._platform.logger.wrapOrRun(log, "create room", log => { const localId = `local-${Math.round(this._platform.random() * Math.MAX_SAFE_INTEGER)}`; const roomBeingCreated = new RoomBeingCreated(localId, type, isEncrypted, explicitName, topic, invites, this._roomsBeingCreatedUpdateCallback, this._mediaRepository, log); this._roomsBeingCreated.set(localId, roomBeingCreated); log.wrapDetached("create room network", log => { - return roomBeingCreated.start(this._hsApi, log); + const promises = [roomBeingCreated.create(this._hsApi, log)]; + if (options?.loadProfiles) { + promises.push(roomBeingCreated.loadProfiles(this._hsApi, log)); + } + return Promise.all(promises); }); return roomBeingCreated; }); diff --git a/src/matrix/room/create.ts b/src/matrix/room/create.ts index 83b68d3f..66714d72 100644 --- a/src/matrix/room/create.ts +++ b/src/matrix/room/create.ts @@ -92,14 +92,7 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> { } } - public async start(hsApi: HomeServerApi, log: ILogItem): Promise { - await Promise.all([ - this.loadProfiles(hsApi, log), - this.create(hsApi, log), - ]); - } - - private async create(hsApi: HomeServerApi, log: ILogItem): Promise { + async create(hsApi: HomeServerApi, log: ILogItem): Promise { const options: CreateRoomPayload = { is_direct: this.type === RoomType.DirectMessage, preset: presetForType(this.type) @@ -125,7 +118,12 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> { this.emitChange(undefined, log); } - private async loadProfiles(hsApi: HomeServerApi, log: ILogItem): Promise { + /** requests the profiles of the invitees if needed to give an accurate + * estimated room name in case an explicit room name is not set. + * The room is being created in the background whether this is called + * or not, and this just gives a more accurate name while that request + * is running. */ + async loadProfiles(hsApi: HomeServerApi, log: ILogItem): Promise { // only load profiles if we need it for the room name and avatar if (!this.explicitName && this.inviteUserIds) { this.profiles = await loadProfiles(this.inviteUserIds, hsApi, log);