From d788d22aa0357edad015e64b320769813d49dac0 Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Wed, 6 Oct 2021 11:49:17 +0200 Subject: [PATCH] refactor(@desktop/timeline): use new file and store architecture This refactors the timeline module to follow the stores/views/panel/popups architecture. It extracts all usages of *Model context variables with store instance equivalents and replaces API calls on such model instances with store proxy APIs. Closes #3713 --- ui/app/AppLayouts/Timeline/TimelineLayout.qml | 28 ++++++++++++------- .../EmptyTimelinePanel.qml} | 11 +++++--- .../AppLayouts/Timeline/stores/RootStore.qml | 28 +++++++++++++++++++ 3 files changed, 53 insertions(+), 14 deletions(-) rename ui/app/AppLayouts/Timeline/{EmptyTimeline.qml => panels/EmptyTimelinePanel.qml} (90%) create mode 100644 ui/app/AppLayouts/Timeline/stores/RootStore.qml diff --git a/ui/app/AppLayouts/Timeline/TimelineLayout.qml b/ui/app/AppLayouts/Timeline/TimelineLayout.qml index 1a0a549b6c..509ca71025 100644 --- a/ui/app/AppLayouts/Timeline/TimelineLayout.qml +++ b/ui/app/AppLayouts/Timeline/TimelineLayout.qml @@ -7,12 +7,17 @@ import QtQuick.Layouts 1.13 import utils 1.0 import "../../../shared" import "../../../shared/status" -import "../Chat/data" import "../Chat/ChatColumn" import "../Chat/components" +import "stores" +import "panels" + ScrollView { id: root + + property RootStore store: RootStore { } + Layout.fillWidth: true Layout.fillHeight: true contentHeight: chatLogView.contentHeight + 140 @@ -20,7 +25,7 @@ ScrollView { ScrollBar.horizontal.policy: ScrollBar.AlwaysOff property var onActivated: function () { - chatsModel.setActiveChannelToTimeline() + store.setActiveChannelToTimeline() statusUpdateInput.textInput.forceActiveFocus(Qt.MouseFocusReason) } @@ -33,7 +38,7 @@ ScrollView { if(parentPopup){ popup.parentPopup = parentPopup; } - popup.openPopup(profileModel.profile.pubKey !== fromAuthorParam, userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam); + popup.openPopup(root.store.profileModelInst.profile.pubKey !== fromAuthorParam, userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam); } StatusImageModal { @@ -60,6 +65,7 @@ ScrollView { anchors.horizontalCenter: parent.horizontalCenter anchors.bottom: parent.bottom + // TODO: Replace this with StatusQ component once it lives there. StatusChatInput { id: statusUpdateInput anchors.top: parent.top @@ -70,13 +76,13 @@ ScrollView { onSendMessage: { if (statusUpdateInput.fileUrls.length > 0){ statusUpdateInput.fileUrls.forEach(url => { - chatsModel.sendImage(url, true); + root.store.sendImage(url); }) } - var msg = chatsModel.plainText(Emoji.deparse(statusUpdateInput.textInput.text)) + var msg = root.store.getPlainTextFromRichText(Emoji.deparse(statusUpdateInput.textInput.text)) if (msg.length > 0){ msg = statusUpdateInput.interpretMessage(msg) - chatsModel.messageView.sendMessage(msg, "", Utils.isOnlyEmoji(msg) ? Constants.emojiType : Constants.messageType, true); + root.store.sendMessage(msg, Utils.isOnlyEmoji(msg) ? Constants.emojiType : Constants.messageType); statusUpdateInput.textInput.text = ""; if(event) event.accepted = true sendMessageSound.stop() @@ -85,7 +91,7 @@ ScrollView { } } - EmptyTimeline { + EmptyTimelinePanel { id: emptyTimeline anchors.top: statusUpdateInput.bottom anchors.topMargin: 40 @@ -109,7 +115,7 @@ ScrollView { section.criteria: ViewSection.FullString Connections { - target: chatsModel.messageView + target: root.store.chatsModelInst.messageView onMessagesLoaded: { Qt.callLater(chatLogView.positionViewAtBeginning) } @@ -131,7 +137,8 @@ ScrollView { function(left, right) { return left.clock > right.clock } ] - model: chatsModel.messageView.messageList + model: root.store.chatsModelInst.messageView.messageList + // TODO: Replace with StatusQ component once it lives there. delegate: Message { id: msgDelegate fromAuthor: model.fromAuthor @@ -173,7 +180,8 @@ ScrollView { } Loader { - active: chatsModel.messageView.loadingMessages + active: root.store.chatsModelInst.messageView.loadingMessages + // TODO: replace with StatusLoadingIndicator sourceComponent: LoadingAnimation {} anchors.right: timelineContainer.right anchors.top: statusUpdateInput.bottom diff --git a/ui/app/AppLayouts/Timeline/EmptyTimeline.qml b/ui/app/AppLayouts/Timeline/panels/EmptyTimelinePanel.qml similarity index 90% rename from ui/app/AppLayouts/Timeline/EmptyTimeline.qml rename to ui/app/AppLayouts/Timeline/panels/EmptyTimelinePanel.qml index 3bc22ce777..794c72e9c3 100644 --- a/ui/app/AppLayouts/Timeline/EmptyTimeline.qml +++ b/ui/app/AppLayouts/Timeline/panels/EmptyTimelinePanel.qml @@ -2,9 +2,11 @@ import QtQuick 2.13 import QtQuick.Controls 2.13 import QtQuick.Layouts 1.13 +import StatusQ.Core 0.1 +import StatusQ.Core.Theme 0.1 + import utils 1.0 -import "../../../shared" -import "../../../shared/status" +import "../../../../shared" Rectangle { id: root @@ -34,7 +36,7 @@ Rectangle { width: 255 height: shareYourMindText.height + Style.current.padding - StyledText { + StatusBaseText { id: shareYourMindText horizontalAlignment: Text.AlignHCenter anchors.left: parent.left @@ -45,8 +47,9 @@ Rectangle { //% "Share what's on your mind and stay updated with your contacts" text: qsTrId("share-what-s-on-your-mind-and-stay-updated-with-your-contacts") font.pixelSize: 15 - color: Style.current.secondaryText + color: Theme.palette.directColor7 wrapMode: Text.WordWrap } } } + diff --git a/ui/app/AppLayouts/Timeline/stores/RootStore.qml b/ui/app/AppLayouts/Timeline/stores/RootStore.qml new file mode 100644 index 0000000000..8beeb6bd0d --- /dev/null +++ b/ui/app/AppLayouts/Timeline/stores/RootStore.qml @@ -0,0 +1,28 @@ +import QtQuick 2.13 +import QtQuick.Dialogs 1.3 + +import utils 1.0 + +QtObject { + id: root + + property var chatsModelInst: chatsModel + property var profileModelInst: profileModel + + function setActiveChannelToTimeline() { + chatsModelInst.setActiveChannelToTimeline() + } + + function getPlainTextFromRichText(text) { + return chatsModelInst.plainText(text) + } + + function sendMessage(message, contentType) { + chatsModelInst.messageView.sendMessage(message, "", contentType, true) + } + + function sendImage(url) { + chatsModelInst.sendImage(url, true) + } + +}