diff --git a/src/matrix/net/HomeServerApi.js b/src/matrix/net/HomeServerApi.js index ba4adb7f..234c8bc3 100644 --- a/src/matrix/net/HomeServerApi.js +++ b/src/matrix/net/HomeServerApi.js @@ -136,6 +136,11 @@ export class HomeServerApi { return this._put(`/rooms/${encodeURIComponent(roomId)}/send/${encodeURIComponent(eventType)}/${encodeURIComponent(txnId)}`, {}, content, options); } + receipt(roomId, receiptType, eventId, options = null) { + return this._post(`/rooms/${encodeURIComponent(roomId)}/receipt/${encodeURIComponent(receiptType)}/${encodeURIComponent(eventId)}`, + {}, {}, options); + } + passwordLogin(username, password, options = null) { return this._post("/login", null, { "type": "m.login.password", diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 760b7f08..8797e7a5 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -201,8 +201,23 @@ export class Room extends EventEmitter { return this._summary.notificationCount; } + async _getLastEventId() { + const lastKey = this._syncWriter.lastMessageKey; + if (lastKey) { + const txn = await this._storage.readTxn([ + this._storage.storeNames.timelineEvents, + ]); + const eventEntry = await txn.timelineEvents.get(this._roomId, lastKey); + return eventEntry?.event?.event_id; + } + } + async clearUnread() { - if (this.isUnread) { + 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, ]); diff --git a/src/matrix/room/timeline/persistence/SyncWriter.js b/src/matrix/room/timeline/persistence/SyncWriter.js index 5cbd6779..7dd53129 100644 --- a/src/matrix/room/timeline/persistence/SyncWriter.js +++ b/src/matrix/room/timeline/persistence/SyncWriter.js @@ -209,6 +209,10 @@ export class SyncWriter { afterSync(newLiveKey) { this._lastLiveKey = newLiveKey; } + + get lastMessageKey() { + return this._lastLiveKey; + } } //import MemoryStorage from "../storage/memory/MemoryStorage.js";