diff --git a/src/domain/ViewModel.js b/src/domain/ViewModel.js index 15812f8c..7f973ad7 100644 --- a/src/domain/ViewModel.js +++ b/src/domain/ViewModel.js @@ -25,6 +25,7 @@ export class ViewModel extends EventEmitter { constructor({clock, emitChange} = {}) { super(); this.disposables = null; + this._isDisposed = false; this._options = {clock, emitChange}; } @@ -43,6 +44,11 @@ export class ViewModel extends EventEmitter { if (this.disposables) { this.disposables.dispose(); } + this._isDisposed = true; + } + + get isDisposed() { + return this._isDisposed; } disposeTracked(disposable) { diff --git a/src/domain/session/room/timeline/TimelineViewModel.js b/src/domain/session/room/timeline/TimelineViewModel.js index 16d529cb..a4f662f6 100644 --- a/src/domain/session/room/timeline/TimelineViewModel.js +++ b/src/domain/session/room/timeline/TimelineViewModel.js @@ -50,6 +50,10 @@ export class TimelineViewModel extends ViewModel { * @return {bool} startReached if the start of the timeline was reached */ async loadAtTop() { + if (this.isDisposed) { + // stop loading more, we switched room + return true; + } const firstTile = this._tiles.getFirst(); if (firstTile.shape === "gap") { return firstTile.fill();