forked from mystiq/hydrogen-web
better error handling in RoomBeingCreated
This commit is contained in:
parent
d6d1af13d0
commit
f12841b2d3
1 changed files with 49 additions and 47 deletions
|
@ -117,44 +117,44 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
async create(hsApi: HomeServerApi, log: ILogItem): Promise<void> {
|
async create(hsApi: HomeServerApi, log: ILogItem): Promise<void> {
|
||||||
let avatarEventContent;
|
|
||||||
if (this.options.avatar) {
|
|
||||||
const {avatar} = this.options;
|
|
||||||
const attachment = new AttachmentUpload({filename: avatar.name, blob: avatar.blob, platform: this.platform});
|
|
||||||
await attachment.upload(hsApi, () => {}, log);
|
|
||||||
avatarEventContent = {
|
|
||||||
info: avatar.info
|
|
||||||
};
|
|
||||||
attachment.applyToContent("url", avatarEventContent);
|
|
||||||
}
|
|
||||||
const createOptions: CreateRoomPayload = {
|
|
||||||
is_direct: this.options.type === RoomType.DirectMessage,
|
|
||||||
preset: presetForType(this.options.type),
|
|
||||||
initial_state: []
|
|
||||||
};
|
|
||||||
if (this.options.name) {
|
|
||||||
createOptions.name = this.options.name;
|
|
||||||
}
|
|
||||||
if (this.options.topic) {
|
|
||||||
createOptions.topic = this.options.topic;
|
|
||||||
}
|
|
||||||
if (this.options.invites) {
|
|
||||||
createOptions.invite = this.options.invites;
|
|
||||||
}
|
|
||||||
if (this.options.alias) {
|
|
||||||
createOptions.room_alias_name = this.options.alias;
|
|
||||||
}
|
|
||||||
if (this.isEncrypted) {
|
|
||||||
createOptions.initial_state.push(createRoomEncryptionEvent());
|
|
||||||
}
|
|
||||||
if (avatarEventContent) {
|
|
||||||
createOptions.initial_state.push({
|
|
||||||
type: "m.room.avatar",
|
|
||||||
state_key: "",
|
|
||||||
content: avatarEventContent
|
|
||||||
});
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
let avatarEventContent;
|
||||||
|
if (this.options.avatar) {
|
||||||
|
const {avatar} = this.options;
|
||||||
|
const attachment = new AttachmentUpload({filename: avatar.name, blob: avatar.blob, platform: this.platform});
|
||||||
|
await attachment.upload(hsApi, () => {}, log);
|
||||||
|
avatarEventContent = {
|
||||||
|
info: avatar.info
|
||||||
|
};
|
||||||
|
attachment.applyToContent("url", avatarEventContent);
|
||||||
|
}
|
||||||
|
const createOptions: CreateRoomPayload = {
|
||||||
|
is_direct: this.options.type === RoomType.DirectMessage,
|
||||||
|
preset: presetForType(this.options.type),
|
||||||
|
initial_state: []
|
||||||
|
};
|
||||||
|
if (this.options.name) {
|
||||||
|
createOptions.name = this.options.name;
|
||||||
|
}
|
||||||
|
if (this.options.topic) {
|
||||||
|
createOptions.topic = this.options.topic;
|
||||||
|
}
|
||||||
|
if (this.options.invites) {
|
||||||
|
createOptions.invite = this.options.invites;
|
||||||
|
}
|
||||||
|
if (this.options.alias) {
|
||||||
|
createOptions.room_alias_name = this.options.alias;
|
||||||
|
}
|
||||||
|
if (this.isEncrypted) {
|
||||||
|
createOptions.initial_state.push(createRoomEncryptionEvent());
|
||||||
|
}
|
||||||
|
if (avatarEventContent) {
|
||||||
|
createOptions.initial_state.push({
|
||||||
|
type: "m.room.avatar",
|
||||||
|
state_key: "",
|
||||||
|
content: avatarEventContent
|
||||||
|
});
|
||||||
|
}
|
||||||
const response = await hsApi.createRoom(createOptions, {log}).response();
|
const response = await hsApi.createRoom(createOptions, {log}).response();
|
||||||
this._roomId = response["room_id"];
|
this._roomId = response["room_id"];
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -170,16 +170,18 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
||||||
* is running. */
|
* is running. */
|
||||||
/** @internal */
|
/** @internal */
|
||||||
async loadProfiles(hsApi: HomeServerApi, log: ILogItem): Promise<void> {
|
async loadProfiles(hsApi: HomeServerApi, log: ILogItem): Promise<void> {
|
||||||
// only load profiles if we need it for the room name and avatar
|
try {
|
||||||
if (!this.options.name && this.options.invites) {
|
// only load profiles if we need it for the room name and avatar
|
||||||
this.profiles = await loadProfiles(this.options.invites, hsApi, log);
|
if (!this.options.name && this.options.invites) {
|
||||||
const summaryData = {
|
this.profiles = await loadProfiles(this.options.invites, hsApi, log);
|
||||||
joinCount: 1, // ourselves
|
const summaryData = {
|
||||||
inviteCount: this.options.invites.length
|
joinCount: 1, // ourselves
|
||||||
};
|
inviteCount: this.options.invites.length
|
||||||
this._calculatedName = calculateRoomName(this.profiles, summaryData, log);
|
};
|
||||||
this.emitChange();
|
this._calculatedName = calculateRoomName(this.profiles, summaryData, log);
|
||||||
}
|
this.emitChange();
|
||||||
|
}
|
||||||
|
} catch (err) {} // swallow error, loading profiles is not essential
|
||||||
}
|
}
|
||||||
|
|
||||||
private emitChange(params?: string) {
|
private emitChange(params?: string) {
|
||||||
|
|
Loading…
Reference in a new issue