From 109389513332926ff21e2112a08d638c281910d2 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 24 Feb 2021 11:21:04 +0100 Subject: [PATCH 1/5] 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() { From 376e59820c441c18330aa3b9779d0c3c096ad121 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 24 Feb 2021 11:22:07 +0100 Subject: [PATCH 2/5] more info when logging gap fills --- src/matrix/room/Room.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 37035b9d..d35aa93f 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -408,7 +408,11 @@ export class Room extends EventEmitter { fillGap(fragmentEntry, amount, log = null) { // TODO move some/all of this out of Room return this._platform.logger.wrapOrRun(log, "fillGap", async log => { + log.set("id", this.id); + log.set("fragment", fragmentEntry.fragmentId); + log.set("dir", fragmentEntry.direction.asApiString()); if (fragmentEntry.edgeReached) { + log.set("edgeReached", true); return; } const response = await this._hsApi.messages(this._roomId, { From 48c361531d6df41ea12a380da356c2e4396dc9d5 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 24 Feb 2021 11:22:19 +0100 Subject: [PATCH 3/5] log clearing unread state of a room --- src/matrix/room/Room.js | 51 ++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index d35aa93f..caf4ea83 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -548,33 +548,36 @@ export class Room extends EventEmitter { this._emitCollectionChange(this); } - async clearUnread() { + async clearUnread(log = null) { if (this.isUnread || this.notificationCount) { - const txn = this._storage.readWriteTxn([ - this._storage.storeNames.roomSummary, - ]); - let data; - try { - data = this._summary.writeClearUnread(txn); - } catch (err) { - txn.abort(); - throw err; - } - await txn.complete(); - this._summary.applyChanges(data); - this._emitUpdate(); - - try { - const lastEventId = await this._getLastEventId(); - if (lastEventId) { - await this._hsApi.receipt(this._roomId, "m.read", lastEventId); - } - } catch (err) { - // ignore ConnectionError - if (err.name !== "ConnectionError") { + return await this._platform.logger.wrapOrRun(log, "clearUnread", async log => { + log.set("id", this.id); + const txn = this._storage.readWriteTxn([ + this._storage.storeNames.roomSummary, + ]); + let data; + try { + data = this._summary.writeClearUnread(txn); + } catch (err) { + txn.abort(); throw err; } - } + await txn.complete(); + this._summary.applyChanges(data); + this._emitUpdate(); + + try { + const lastEventId = await this._getLastEventId(); + if (lastEventId) { + await this._hsApi.receipt(this._roomId, "m.read", lastEventId); + } + } catch (err) { + // ignore ConnectionError + if (err.name !== "ConnectionError") { + throw err; + } + } + }); } } From b63ad629a74a284854c9770fde579ade46ebcc73 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 24 Feb 2021 11:25:26 +0100 Subject: [PATCH 4/5] can remove console logging here now --- src/matrix/room/Room.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index caf4ea83..e626116e 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -588,7 +588,6 @@ export class Room extends EventEmitter { 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, From 139ffc954872db87a423657eae95e071f5e7275b Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 24 Feb 2021 11:30:32 +0100 Subject: [PATCH 5/5] explain sent file names are logged because they are in the url of the upload request, which we log --- src/platform/web/ui/session/settings/SettingsView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/web/ui/session/settings/SettingsView.js b/src/platform/web/ui/session/settings/SettingsView.js index 84441cbb..02e57f5e 100644 --- a/src/platform/web/ui/session/settings/SettingsView.js +++ b/src/platform/web/ui/session/settings/SettingsView.js @@ -52,7 +52,7 @@ export class SettingsView extends TemplateView { row(vm.i18n`Version`, version), row(vm.i18n`Storage usage`, vm => `${vm.storageUsage} / ${vm.storageQuota}`), row(vm.i18n`Debug logs`, t.button({onClick: () => vm.exportLogs()}, "Export")), - t.p(["Debug logs contain application usage data including your username, the IDs or aliases of the rooms or groups you have visited and the usernames of other users. They do not contain messages. For more information, review our ", + t.p(["Debug logs contain application usage data including your username, the IDs or aliases of the rooms or groups you have visited, the usernames of other users and the names of files you send. They do not contain messages. For more information, review our ", t.a({href: "https://element.io/privacy", target: "_blank", rel: "noopener"}, "privacy policy"), "."]), ]) ]);