From 739d74bf9c0b024265a108607e3fcfea1e174c33 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 21 Aug 2020 11:56:10 +0200 Subject: [PATCH] add method to clear unread state --- src/matrix/room/Room.js | 17 +++++++++++++++++ src/matrix/room/RoomSummary.js | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 5ac77009..75978b27 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -184,6 +184,23 @@ export class Room extends EventEmitter { return this._summary.avatarUrl; } + 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; + } + await txn.complete(); + this._summary.applyChanges(data); + this.emit("change"); + this._emitCollectionChange(this); + } + /** @public */ async openTimeline() { if (this._timeline) { diff --git a/src/matrix/room/RoomSummary.js b/src/matrix/room/RoomSummary.js index bb74656f..399d869b 100644 --- a/src/matrix/room/RoomSummary.js +++ b/src/matrix/room/RoomSummary.js @@ -191,6 +191,15 @@ export class RoomSummary { return this._data.lastPaginationToken; } + writeClearUnread(txn) { + const data = new SummaryData(this._data); + data.isUnread = false; + data.notificationCount = 0; + data.highlightCount = 0; + txn.roomSummary.set(data.serialize()); + return data; + } + writeHasFetchedMembers(value, txn) { const data = new SummaryData(this._data); data.hasFetchedMembers = value;