From 0d8ff34c5554a283c7e54c9ea16c26fba88ab46e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 21 Aug 2020 15:23:25 +0200 Subject: [PATCH] don't fail to clear unread state when offline also update UI before network request --- src/matrix/room/Room.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 8797e7a5..158299c3 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -214,10 +214,6 @@ export class Room extends EventEmitter { async clearUnread() { if (this.isUnread || this.notificationCount) { - const lastEventId = await this._getLastEventId(); - if (lastEventId) { - await this._hsApi.receipt(this._roomId, "m.read", lastEventId); - } const txn = await this._storage.readWriteTxn([ this._storage.storeNames.roomSummary, ]); @@ -232,6 +228,18 @@ export class Room extends EventEmitter { this._summary.applyChanges(data); this.emit("change"); this._emitCollectionChange(this); + + 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; + } + } } }