diff --git a/src/domain/session/room/ComposerViewModel.js b/src/domain/session/room/ComposerViewModel.js index 3ae11872..6aa22b62 100644 --- a/src/domain/session/room/ComposerViewModel.js +++ b/src/domain/session/room/ComposerViewModel.js @@ -6,14 +6,46 @@ export class ComposerViewModel extends ViewModel { this._roomVM = roomVM; this._isEmpty = true; this._replyVM = null; + this._replySub = null; + this._replyingToId = null; } - setReplyingTo(tile) { - const changed = this._replyVM !== tile; - this._replyVM = tile; - if (changed) { - this.emitChange("replyViewModel"); + setReplyingTo(id) { + if (this._replyingToId === id) { + return; } + this._replyingToId = id; + // Dispose of event subscription + if (this._replySub) { + this._replySub(); + this.untrack(this._replySub); + } + // replyVM may not be created yet even if subscribed. + if (this._replyVM) { + this._replyVM.dispose(); + } + // Early return if we don't have an ID to reply to. + if (!id) { + this._replyVM = null; + this._replySub = null; + this.emitChange("replyViewModel"); + return; + } + const observable = this._roomVM._observeEvent(id); + const entry = observable.get(); + if (entry) { + this._replyVM = this._roomVM._createTile(entry); + } + this._replySub = observable.subscribe(entry => { + if (!this._replyVM) { + this._replyVM = this._roomVM._createTile(entry); + } else { + this._replyVM.updateEntry(entry); + } + this.emitChange("replyViewModel"); + }); + this.track(this._replySub); + this.emitChange("replyViewModel"); } clearReplyingTo() { diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index d36713bf..7b1347c8 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -306,11 +306,19 @@ export class RoomViewModel extends ViewModel { this.navigation.applyPath(path); } - startReply(entry) { + startReply(id) { if (!this._room.isArchived) { - this._composerVM.setReplyingTo(entry); + this._composerVM.setReplyingTo(id); } } + + _createTile(entry) { + return this._tilesCreator(entry); + } + + _observeEvent(eventId) { + return this._room.observeEvent(eventId); + } } function imageToInfo(image) { diff --git a/src/domain/session/room/timeline/tiles/BaseMessageTile.js b/src/domain/session/room/timeline/tiles/BaseMessageTile.js index eef83cb6..d78b85e4 100644 --- a/src/domain/session/room/timeline/tiles/BaseMessageTile.js +++ b/src/domain/session/room/timeline/tiles/BaseMessageTile.js @@ -107,7 +107,7 @@ export class BaseMessageTile extends SimpleTile { } startReply() { - this._roomVM.startReply(this); + this._roomVM.startReply(this._entry.id); } reply(msgtype, body, log = null) {