From 1a0e3052127351311f2f5c0979fc3e35421b0d62 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 3 Aug 2021 14:02:11 -0700 Subject: [PATCH] Extract ComposerViewModel to its own file --- src/domain/session/room/ComposerViewModel.js | 71 ++++++++++++++++++++ src/domain/session/room/RoomViewModel.js | 71 +------------------- 2 files changed, 72 insertions(+), 70 deletions(-) create mode 100644 src/domain/session/room/ComposerViewModel.js diff --git a/src/domain/session/room/ComposerViewModel.js b/src/domain/session/room/ComposerViewModel.js new file mode 100644 index 00000000..3ae11872 --- /dev/null +++ b/src/domain/session/room/ComposerViewModel.js @@ -0,0 +1,71 @@ +import {ViewModel} from "../../ViewModel.js"; + +export class ComposerViewModel extends ViewModel { + constructor(roomVM) { + super(); + this._roomVM = roomVM; + this._isEmpty = true; + this._replyVM = null; + } + + setReplyingTo(tile) { + const changed = this._replyVM !== tile; + this._replyVM = tile; + if (changed) { + this.emitChange("replyViewModel"); + } + } + + clearReplyingTo() { + this.setReplyingTo(null); + } + + get replyViewModel() { + return this._replyVM; + } + + get isEncrypted() { + return this._roomVM.isEncrypted; + } + + sendMessage(message) { + const success = this._roomVM._sendMessage(message, this._replyVM); + if (success) { + this._isEmpty = true; + this.emitChange("canSend"); + this.clearReplyingTo(); + } + return success; + } + + sendPicture() { + this._roomVM._pickAndSendPicture(); + } + + sendFile() { + this._roomVM._pickAndSendFile(); + } + + sendVideo() { + this._roomVM._pickAndSendVideo(); + } + + get canSend() { + return !this._isEmpty; + } + + async setInput(text) { + const wasEmpty = this._isEmpty; + this._isEmpty = text.length === 0; + if (wasEmpty && !this._isEmpty) { + this._roomVM._room.ensureMessageKeyIsShared(); + } + if (wasEmpty !== this._isEmpty) { + this.emitChange("canSend"); + } + } + + get kind() { + return "composer"; + } +} diff --git a/src/domain/session/room/RoomViewModel.js b/src/domain/session/room/RoomViewModel.js index 151af2e6..11f08df1 100644 --- a/src/domain/session/room/RoomViewModel.js +++ b/src/domain/session/room/RoomViewModel.js @@ -16,6 +16,7 @@ limitations under the License. */ import {TimelineViewModel} from "./timeline/TimelineViewModel.js"; +import {ComposerViewModel} from "./ComposerViewModel.js" import {avatarInitials, getIdentifierColorNumber, getAvatarHttpUrl} from "../../avatar.js"; import {ViewModel} from "../../ViewModel.js"; @@ -307,76 +308,6 @@ export class RoomViewModel extends ViewModel { } } -class ComposerViewModel extends ViewModel { - constructor(roomVM) { - super(); - this._roomVM = roomVM; - this._isEmpty = true; - this._replyVM = null; - } - - setReplyingTo(tile) { - const changed = this._replyVM !== tile; - this._replyVM = tile; - if (changed) { - this.emitChange("replyViewModel"); - } - } - - clearReplyingTo() { - this.setReplyingTo(null); - } - - get replyViewModel() { - return this._replyVM; - } - - get isEncrypted() { - return this._roomVM.isEncrypted; - } - - sendMessage(message) { - const success = this._roomVM._sendMessage(message, this._replyVM); - if (success) { - this._isEmpty = true; - this.emitChange("canSend"); - this.clearReplyingTo(); - } - return success; - } - - sendPicture() { - this._roomVM._pickAndSendPicture(); - } - - sendFile() { - this._roomVM._pickAndSendFile(); - } - - sendVideo() { - this._roomVM._pickAndSendVideo(); - } - - get canSend() { - return !this._isEmpty; - } - - async setInput(text) { - const wasEmpty = this._isEmpty; - this._isEmpty = text.length === 0; - if (wasEmpty && !this._isEmpty) { - this._roomVM._room.ensureMessageKeyIsShared(); - } - if (wasEmpty !== this._isEmpty) { - this.emitChange("canSend"); - } - } - - get kind() { - return "composer"; - } -} - function imageToInfo(image) { return { w: image.width,