diff --git a/src/domain/session/room/ComposerViewModel.js b/src/domain/session/room/ComposerViewModel.js index 6aa22b62..c833f101 100644 --- a/src/domain/session/room/ComposerViewModel.js +++ b/src/domain/session/room/ComposerViewModel.js @@ -23,10 +23,10 @@ export class ComposerViewModel extends ViewModel { // replyVM may not be created yet even if subscribed. if (this._replyVM) { this._replyVM.dispose(); + this._replyVM = null; } // Early return if we don't have an ID to reply to. if (!id) { - this._replyVM = null; this._replySub = null; this.emitChange("replyViewModel"); return; @@ -40,7 +40,7 @@ export class ComposerViewModel extends ViewModel { if (!this._replyVM) { this._replyVM = this._roomVM._createTile(entry); } else { - this._replyVM.updateEntry(entry); + this._updateReplyEntry(entry); } this.emitChange("replyViewModel"); }); @@ -48,6 +48,20 @@ export class ComposerViewModel extends ViewModel { this.emitChange("replyViewModel"); } + _updateReplyEntry(entry) { + const update = this._replyVM.updateEntry(entry); + if (update.shouldReplace) { + const newTile = this._roomVM._createTile(entry); + this._replyVM.dispose(); + this._replyVM = newTile || null; + } else if (update.shouldRemove) { + this._replyVM.dispose(); + this._replyVM = null; + } else if (update.shouldUpdate) { + // Nothing, since we'll be calling emitChange anyway. + } + } + clearReplyingTo() { this.setReplyingTo(null); }