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
This commit is contained in:
Pascal Precht 2021-10-06 11:49:17 +02:00 committed by Iuri Matias
parent 6379b17d95
commit d788d22aa0
3 changed files with 53 additions and 14 deletions

View File

@ -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

View File

@ -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
}
}
}

View File

@ -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)
}
}