From dc1357bb316094ffb5b140af9441a362c661c6bb Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 7 Oct 2020 12:30:46 +0200 Subject: [PATCH] support clearing unread when focusing a room --- src/domain/session/room/RoomViewModel.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index ab453e01..87d0cb6c 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -51,10 +51,18 @@ export class RoomViewModel extends ViewModel { this._timelineError = err; this.emitChange("error"); } + this._clearUnreadAfterDelay(); + } + + async _clearUnreadAfterDelay() { + if (this._clearUnreadTimout) { + return; + } this._clearUnreadTimout = this.clock.createTimeout(2000); try { await this._clearUnreadTimout.elapsed(); await this._room.clearUnread(); + this._clearUnreadTimout = null; } catch (err) { if (err.name !== "AbortError") { throw err; @@ -62,6 +70,10 @@ export class RoomViewModel extends ViewModel { } } + focus() { + this._clearUnreadAfterDelay(); + } + dispose() { super.dispose(); if (this._clearUnreadTimout) {