From 48c361531d6df41ea12a380da356c2e4396dc9d5 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 24 Feb 2021 11:22:19 +0100 Subject: [PATCH] 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; + } + } + }); } }