From f3f07a0672168ecd33b6c666a979f25346e4092d Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 14 Sep 2020 16:33:43 +0200 Subject: [PATCH] centralize update emitting in room --- src/matrix/room/Room.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 3779f1c3..3a8e7c5d 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -231,8 +231,7 @@ export class Room extends EventEmitter { } } if (emitChange) { - this.emit("change"); - this._emitCollectionChange(this); + this._emitUpdate(); } if (this._timeline) { this._timeline.appendLiveEntries(newTimelineEntries); @@ -442,6 +441,13 @@ export class Room extends EventEmitter { return !!this._timeline; } + _emitUpdate() { + // once for event emitter listeners + this.emit("change"); + // and once for collection listeners + this._emitCollectionChange(this); + } + async clearUnread() { if (this.isUnread || this.notificationCount) { const txn = await this._storage.readWriteTxn([ @@ -456,8 +462,7 @@ export class Room extends EventEmitter { } await txn.complete(); this._summary.applyChanges(data); - this.emit("change"); - this._emitCollectionChange(this); + this._emitUpdate(); try { const lastEventId = await this._getLastEventId();