From dbf5e59d874af384c1399af3166c6bcadd7d8b92 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 21 Aug 2020 11:57:49 +0200 Subject: [PATCH] clear unread state 2s after opening the room --- src/domain/session/room/RoomViewModel.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index 86edf027..b5c05be7 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -32,6 +32,7 @@ export class RoomViewModel extends ViewModel { this._sendError = null; this._closeCallback = closeCallback; this._composerVM = new ComposerViewModel(this); + this._clearUnreadTimout = null; } async load() { @@ -49,6 +50,15 @@ export class RoomViewModel extends ViewModel { this._timelineError = err; this.emitChange("error"); } + this._clearUnreadTimout = this.clock.createTimeout(2000); + try { + await this._clearUnreadTimout.elapsed(); + await this._room.clearUnread(); + } catch (err) { + if (err.name !== "AbortError") { + throw err; + } + } } dispose() { @@ -57,6 +67,10 @@ export class RoomViewModel extends ViewModel { // will stop the timeline from delivering updates on entries this._timeline.close(); } + if (this._clearUnreadTimout) { + this._clearUnreadTimout.abort(); + this._clearUnreadTimout = null; + } } close() {