forked from mystiq/hydrogen-web
cleanup logging
This commit is contained in:
parent
d7b024eac1
commit
5325b0b466
3 changed files with 31 additions and 25 deletions
|
@ -86,8 +86,10 @@ export class MemberDetailsViewModel extends ViewModel {
|
|||
const room = this._session.findDirectMessageForUserId(this.userId);
|
||||
let roomId = room?.id;
|
||||
if (!roomId) {
|
||||
const roomBeingCreated = await this._session.createRoom(
|
||||
RoomType.DirectMessage, undefined, undefined, undefined, [this.userId], {loadProfiles: true});
|
||||
const roomBeingCreated = await this._session.createRoom({
|
||||
type: RoomType.DirectMessage,
|
||||
invites: [this.userId]
|
||||
});
|
||||
roomId = roomBeingCreated.localId;
|
||||
}
|
||||
this.navigation.push("room", roomId);
|
||||
|
|
|
@ -64,12 +64,7 @@ export class Session {
|
|||
this._activeArchivedRooms = new Map();
|
||||
this._invites = new ObservableMap();
|
||||
this._inviteUpdateCallback = (invite, params) => this._invites.update(invite.id, params);
|
||||
this._roomsBeingCreatedUpdateCallback = (rbc, params, log) => {
|
||||
this._roomsBeingCreated.update(rbc.localId, params);
|
||||
if (rbc.roomId && !!this.rooms.get(rbc.roomId)) {
|
||||
this._tryReplaceRoomBeingCreated(rbc.roomId, log);
|
||||
}
|
||||
};
|
||||
this._roomsBeingCreatedUpdateCallback = (rbc, params) => this._roomsBeingCreated.update(rbc.localId, params);
|
||||
this._roomsBeingCreated = new ObservableMap();
|
||||
this._user = new User(sessionInfo.userId);
|
||||
this._deviceMessageHandler = new DeviceMessageHandler({storage});
|
||||
|
@ -605,20 +600,27 @@ export class Session {
|
|||
return this._roomsBeingCreated;
|
||||
}
|
||||
|
||||
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);
|
||||
createRoom({type, isEncrypted, explicitName, topic, invites, loadProfiles = true}, log = undefined) {
|
||||
let roomBeingCreated;
|
||||
this._platform.logger.runDetached("create room", async log => {
|
||||
const localId = `local-${Math.floor(this._platform.random() * Number.MAX_SAFE_INTEGER)}`;
|
||||
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 => {
|
||||
const promises = [roomBeingCreated.create(this._hsApi, log)];
|
||||
if (options?.loadProfiles) {
|
||||
promises.push(roomBeingCreated.loadProfiles(this._hsApi, log));
|
||||
}
|
||||
return Promise.all(promises);
|
||||
});
|
||||
return roomBeingCreated;
|
||||
const promises = [roomBeingCreated.create(this._hsApi, log)];
|
||||
if (loadProfiles) {
|
||||
promises.push(roomBeingCreated.loadProfiles(this._hsApi, log));
|
||||
}
|
||||
await Promise.all(promises);
|
||||
// we should now know the roomId, check if the room was synced before we received
|
||||
// the room id. Replace the room being created with the synced room.
|
||||
if (roomBeingCreated.roomId && !!this.rooms.get(roomBeingCreated.roomId)) {
|
||||
this._tryReplaceRoomBeingCreated(roomBeingCreated.roomId, log);
|
||||
}
|
||||
// TODO: if type is DM, then adjust the m.direct account data
|
||||
});
|
||||
return roomBeingCreated;
|
||||
}
|
||||
|
||||
async obtainSyncLock(syncResponse) {
|
||||
|
|
|
@ -74,7 +74,7 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||
private readonly explicitName: string | undefined,
|
||||
private readonly topic: string | undefined,
|
||||
private readonly inviteUserIds: string[] | undefined,
|
||||
private readonly updateCallback,
|
||||
private readonly updateCallback: (self: RoomBeingCreated, params: string | undefined) => void,
|
||||
public readonly mediaRepository: MediaRepository,
|
||||
log: ILogItem
|
||||
) {
|
||||
|
@ -92,6 +92,7 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||
}
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
async create(hsApi: HomeServerApi, log: ILogItem): Promise<void> {
|
||||
const options: CreateRoomPayload = {
|
||||
is_direct: this.type === RoomType.DirectMessage,
|
||||
|
@ -115,7 +116,7 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||
} catch (err) {
|
||||
this._error = err;
|
||||
}
|
||||
this.emitChange(undefined, log);
|
||||
this.emitChange();
|
||||
}
|
||||
|
||||
/** requests the profiles of the invitees if needed to give an accurate
|
||||
|
@ -123,6 +124,7 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||
* 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. */
|
||||
/** @internal */
|
||||
async loadProfiles(hsApi: HomeServerApi, log: ILogItem): Promise<void> {
|
||||
// only load profiles if we need it for the room name and avatar
|
||||
if (!this.explicitName && this.inviteUserIds) {
|
||||
|
@ -136,8 +138,8 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||
}
|
||||
}
|
||||
|
||||
private emitChange(params?, log?: ILogItem) {
|
||||
this.updateCallback(this, params, log);
|
||||
private emitChange(params?: string) {
|
||||
this.updateCallback(this, params);
|
||||
this.emit("change");
|
||||
}
|
||||
|
||||
|
@ -149,7 +151,7 @@ export class RoomBeingCreated extends EventEmitter<{change: never}> {
|
|||
get error(): Error | undefined { return this._error; }
|
||||
|
||||
cancel() {
|
||||
// remove from collection somehow
|
||||
// TODO: remove from collection somehow
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue