add option

This commit is contained in:
Bruno Windels 2022-02-07 18:58:43 +01:00
parent e1fbd1242e
commit 26fa2a5d60
2 changed files with 13 additions and 11 deletions

View File

@ -592,13 +592,17 @@ export class Session {
return this._roomsBeingCreated; 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 => { return this._platform.logger.wrapOrRun(log, "create room", log => {
const localId = `local-${Math.round(this._platform.random() * Math.MAX_SAFE_INTEGER)}`; 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); const roomBeingCreated = new RoomBeingCreated(localId, type, isEncrypted, explicitName, topic, invites, this._roomsBeingCreatedUpdateCallback, this._mediaRepository, log);
this._roomsBeingCreated.set(localId, roomBeingCreated); this._roomsBeingCreated.set(localId, roomBeingCreated);
log.wrapDetached("create room network", log => { 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; return roomBeingCreated;
}); });

View File

@ -92,14 +92,7 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
} }
} }
public async start(hsApi: HomeServerApi, log: ILogItem): Promise<void> { async create(hsApi: HomeServerApi, log: ILogItem): Promise<void> {
await Promise.all([
this.loadProfiles(hsApi, log),
this.create(hsApi, log),
]);
}
private async create(hsApi: HomeServerApi, log: ILogItem): Promise<void> {
const options: CreateRoomPayload = { const options: CreateRoomPayload = {
is_direct: this.type === RoomType.DirectMessage, is_direct: this.type === RoomType.DirectMessage,
preset: presetForType(this.type) preset: presetForType(this.type)
@ -125,7 +118,12 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
this.emitChange(undefined, log); this.emitChange(undefined, log);
} }
private async loadProfiles(hsApi: HomeServerApi, log: ILogItem): Promise<void> { /** 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<void> {
// only load profiles if we need it for the room name and avatar // only load profiles if we need it for the room name and avatar
if (!this.explicitName && this.inviteUserIds) { if (!this.explicitName && this.inviteUserIds) {
this.profiles = await loadProfiles(this.inviteUserIds, hsApi, log); this.profiles = await loadProfiles(this.inviteUserIds, hsApi, log);