From 542690844482013a78afbfb7a208b8288222888d Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 6 Aug 2021 17:49:39 +0200 Subject: [PATCH 1/3] add copyright header --- src/domain/session/room/ComposerViewModel.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/domain/session/room/ComposerViewModel.js b/src/domain/session/room/ComposerViewModel.js index e3ed317c..1f98a21b 100644 --- a/src/domain/session/room/ComposerViewModel.js +++ b/src/domain/session/room/ComposerViewModel.js @@ -1,3 +1,19 @@ +/* +Copyright 2021 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + import {ViewModel} from "../../ViewModel.js"; export class ComposerViewModel extends ViewModel { From 3feaf38252595be95b4521b2a86da7dfd3f1a05e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 6 Aug 2021 17:53:58 +0200 Subject: [PATCH 2/3] use internalId to compare so we don't have to cache the entry id separately --- src/domain/session/room/ComposerViewModel.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/domain/session/room/ComposerViewModel.js b/src/domain/session/room/ComposerViewModel.js index 1f98a21b..d3ee27a0 100644 --- a/src/domain/session/room/ComposerViewModel.js +++ b/src/domain/session/room/ComposerViewModel.js @@ -21,15 +21,12 @@ export class ComposerViewModel extends ViewModel { super(); this._roomVM = roomVM; this._isEmpty = true; - this._replyId = null; this._replyVM = null; } setReplyingTo(entry) { - const newId = entry?.id || null; - const changed = this._replyId !== newId; + const changed = this._replyVM?.internalId !== entry?.asEventKey().toString(); if (changed) { - this._replyId = newId; if (this._replyVM) { this.untrack(this._replyVM); this._replyVM.dispose(); From 2a923633173ece4c498a3a69ecd65c02dea38139 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 6 Aug 2021 17:56:02 +0200 Subject: [PATCH 3/3] use disposeTracked --- src/domain/session/room/ComposerViewModel.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/domain/session/room/ComposerViewModel.js b/src/domain/session/room/ComposerViewModel.js index d3ee27a0..3ee7f8e3 100644 --- a/src/domain/session/room/ComposerViewModel.js +++ b/src/domain/session/room/ComposerViewModel.js @@ -27,13 +27,9 @@ export class ComposerViewModel extends ViewModel { setReplyingTo(entry) { const changed = this._replyVM?.internalId !== entry?.asEventKey().toString(); if (changed) { - if (this._replyVM) { - this.untrack(this._replyVM); - this._replyVM.dispose(); - } - this._replyVM = entry && this._roomVM._createTile(entry); - if (this._replyVM) { - this.track(this._replyVM); + this._replyVM = this.disposeTracked(this._replyVM); + if (entry) { + this._replyVM = this.track(this._roomVM._createTile(entry)); } this.emitChange("replyViewModel"); }