From 2742162c8e18a0d266995d5614542fc025965298 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 21 Aug 2020 14:11:42 +0200 Subject: [PATCH] only clear unread if needed --- src/matrix/room/Room.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index d1da35e4..d3f426a4 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -197,20 +197,22 @@ export class Room extends EventEmitter { } async clearUnread() { - const txn = await this._storage.readWriteTxn([ - this._storage.storeNames.roomSummary, - ]); - let data; - try { - data = this._summary.writeClearUnread(txn); - } catch (err) { - txn.abort(); - throw err; + if (this.isUnread) { + const txn = await 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.emit("change"); + this._emitCollectionChange(this); } - await txn.complete(); - this._summary.applyChanges(data); - this.emit("change"); - this._emitCollectionChange(this); } /** @public */