From 109389513332926ff21e2112a08d638c281910d2 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 24 Feb 2021 11:21:04 +0100 Subject: [PATCH] log opening timeline also load the timeline when opening it in the room, so logging starts in the room (and we don't need to pass the logger to Timeline) and also API-wise it makes more sense to not return uninitialized objects --- src/domain/session/room/RoomViewModel.js | 4 +- .../room/timeline/TimelineViewModel.js | 7 --- src/matrix/room/Room.js | 50 ++++++++++--------- 3 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index 5e6ee998..83910675 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -41,12 +41,12 @@ export class RoomViewModel extends ViewModel { async load() { this._room.on("change", this._onRoomChange); try { + const timeline = await this._room.openTimeline(); const timelineVM = this.track(new TimelineViewModel(this.childOptions({ room: this._room, - timeline: this._room.openTimeline(), + timeline, ownUserId: this._ownUserId, }))); - await timelineVM.load(); this._timelineVM = timelineVM; this.emitChange("timelineViewModel"); } catch (err) { diff --git a/src/domain/session/room/timeline/TimelineViewModel.js b/src/domain/session/room/timeline/TimelineViewModel.js index e3d92171..b40a6dcb 100644 --- a/src/domain/session/room/timeline/TimelineViewModel.js +++ b/src/domain/session/room/timeline/TimelineViewModel.js @@ -40,16 +40,9 @@ export class TimelineViewModel extends ViewModel { super(options); const {room, timeline, ownUserId} = options; this._timeline = this.track(timeline); - // once we support sending messages we could do - // timeline.entries.concat(timeline.pendingEvents) - // for an ObservableList that also contains local echos this._tiles = new TilesCollection(timeline.entries, tilesCreator(this.childOptions({room, ownUserId}))); } - async load() { - await this._timeline.load(); - } - /** * @return {bool} startReached if the start of the timeline was reached */ diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 0ff90ab8..37035b9d 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -575,30 +575,34 @@ export class Room extends EventEmitter { } /** @public */ - openTimeline() { - if (this._timeline) { - throw new Error("not dealing with load race here for now"); - } - console.log(`opening the timeline for ${this._roomId}`); - this._timeline = new Timeline({ - roomId: this.id, - storage: this._storage, - fragmentIdComparer: this._fragmentIdComparer, - pendingEvents: this._sendQueue.pendingEvents, - closeCallback: () => { - console.log(`closing the timeline for ${this._roomId}`); - this._timeline = null; - if (this._roomEncryption) { - this._roomEncryption.notifyTimelineClosed(); - } - }, - user: this._user, - clock: this._platform.clock + openTimeline(log = null) { + return this._platform.logger.wrapOrRun(log, "open timeline", async log => { + log.set("id", this.id); + if (this._timeline) { + throw new Error("not dealing with load race here for now"); + } + console.log(`opening the timeline for ${this._roomId}`); + this._timeline = new Timeline({ + roomId: this.id, + storage: this._storage, + fragmentIdComparer: this._fragmentIdComparer, + pendingEvents: this._sendQueue.pendingEvents, + closeCallback: () => { + this._timeline = null; + if (this._roomEncryption) { + this._roomEncryption.notifyTimelineClosed(); + } + }, + user: this._user, + clock: this._platform.clock, + logger: this._platform.logger, + }); + if (this._roomEncryption) { + this._timeline.enableEncryption(this._decryptEntries.bind(this, DecryptionSource.Timeline)); + } + await this._timeline.load(); + return this._timeline; }); - if (this._roomEncryption) { - this._timeline.enableEncryption(this._decryptEntries.bind(this, DecryptionSource.Timeline)); - } - return this._timeline; } get mediaRepository() {