From cf1ee80dc2aabd9faef4beddb319a350f6eb602a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blak?= Date: Fri, 15 Nov 2024 11:59:50 +0100 Subject: [PATCH] ContactsStore encapsulation improved --- .../Chat/views/MembersSelectorView.qml | 3 +- .../popups/SendContactRequestModal.qml | 3 +- .../Profile/stores/ContactsStore.qml | 73 +++++++++++-------- .../Profile/stores/ProfileSectionStore.qml | 4 +- 4 files changed, 47 insertions(+), 36 deletions(-) diff --git a/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml b/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml index df576bf6c1..50e264cefe 100644 --- a/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml +++ b/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml @@ -154,7 +154,8 @@ MembersSelectorBase { Connections { enabled: root.visible - target: root.rootStore.contactsStore.mainModuleInst + target: root.rootStore.contactsStore + function onResolvedENS(resolvedPubKey: string, resolvedAddress: string, uuid: string) { if (resolvedPubKey === "") { root.suggestionsDialog.forceHide = false diff --git a/ui/app/AppLayouts/Profile/popups/SendContactRequestModal.qml b/ui/app/AppLayouts/Profile/popups/SendContactRequestModal.qml index e13b71a8f2..b9c5666b62 100644 --- a/ui/app/AppLayouts/Profile/popups/SendContactRequestModal.qml +++ b/ui/app/AppLayouts/Profile/popups/SendContactRequestModal.qml @@ -78,7 +78,8 @@ StatusModal { } Connections { - target: contactsStore.mainModuleInst + target: root.contactsStore + function onResolvedENS(resolvedPubKey: string, resolvedAddress: string, uuid: string) { if(!d.showChatKeyValidationIndicator){ d.showPasteButton = false diff --git a/ui/app/AppLayouts/Profile/stores/ContactsStore.qml b/ui/app/AppLayouts/Profile/stores/ContactsStore.qml index acd500a091..c9862a45ea 100644 --- a/ui/app/AppLayouts/Profile/stores/ContactsStore.qml +++ b/ui/app/AppLayouts/Profile/stores/ContactsStore.qml @@ -1,47 +1,58 @@ -import QtQuick 2.13 -import utils 1.0 +import QtQuick 2.15 import StatusQ 0.1 +import utils 1.0 QtObject { id: root - property var contactsModule + readonly property QtObject _d: QtObject { + id: d - property var globalUtilsInst: globalUtils - property var mainModuleInst: Global.appIsReady? mainModule : null + readonly property var contactsModuleInst: profileSectionModule.contactsModule + readonly property var mainModuleInst: mainModule + readonly property var globalUtilsInst: globalUtils + + Component.onCompleted: { + mainModuleInst.resolvedENS.connect(root.resolvedENS) + } + } property string myPublicKey: userProfile.pubKey // contactsModel holds all available contacts - property var contactsModel: contactsModule.contactsModel + property var contactsModel: d.contactsModuleInst.contactsModel readonly property var contactsModelAdaptor: ContactsModelAdaptor { allContacts: contactsModel } + signal resolvedENS(string resolvedPubKey, string resolvedAddress, string uuid) + property var myContactsModel: contactsModelAdaptor.mutualContacts property var blockedContactsModel: contactsModelAdaptor.blockedContacts property var receivedContactRequestsModel: contactsModelAdaptor.pendingReceivedRequestContacts property var sentContactRequestsModel: contactsModelAdaptor.pendingSentRequestContacts - readonly property var showcasePublicKey: contactsModule.showcasePublicKey + readonly property var showcasePublicKey: d.contactsModuleInst.showcasePublicKey // Showcase models for a contact with showcasePublicKey - readonly property var showcaseContactCommunitiesModel: contactsModule.showcaseContactCommunitiesModel - readonly property var showcaseContactAccountsModel: contactsModule.showcaseContactAccountsModel - readonly property var showcaseContactCollectiblesModel: contactsModule.showcaseContactCollectiblesModel - readonly property var showcaseContactAssetsModel: contactsModule.showcaseContactAssetsModel - readonly property var showcaseContactSocialLinksModel: contactsModule.showcaseContactSocialLinksModel + readonly property var showcaseContactCommunitiesModel: d.contactsModuleInst.showcaseContactCommunitiesModel + readonly property var showcaseContactAccountsModel: d.contactsModuleInst.showcaseContactAccountsModel + readonly property var showcaseContactCollectiblesModel: d.contactsModuleInst.showcaseContactCollectiblesModel + readonly property var showcaseContactAssetsModel: d.contactsModuleInst.showcaseContactAssetsModel + readonly property var showcaseContactSocialLinksModel: d.contactsModuleInst.showcaseContactSocialLinksModel - readonly property bool isShowcaseForAContactLoading: contactsModule.showcaseForAContactLoading + readonly property bool isShowcaseForAContactLoading: d.contactsModuleInst.showcaseForAContactLoading // Support models for showcase for a contact with showcasePublicKey - readonly property var showcaseCollectiblesModel: contactsModule.showcaseCollectiblesModel + readonly property var showcaseCollectiblesModel: d.contactsModuleInst.showcaseCollectiblesModel + + signal resolvedENS(string resolvedPubKey, string resolvedAddress, string uuid) // Sets showcasePublicKey and updates showcase models with corresponding data function requestProfileShowcase(publicKey) { - root.contactsModule.requestProfileShowcase(publicKey) + d.contactsModuleInst.requestProfileShowcase(publicKey) } // Temporary commented until we provide appropriate flags on the `status-go` side to cover all sections. @@ -49,32 +60,32 @@ QtObject { // property var sentButRejectedContactRequestsModel: contactsModule.sentButRejectedContactRequestsModel function resolveENS(value) { - root.mainModuleInst.resolveENS(value, "") + d.mainModuleInst.resolveENS(value, "") } function generateAlias(pubKey) { - return root.globalUtilsInst.generateAlias(pubKey) + return d.globalUtilsInst.generateAlias(pubKey) } function joinPrivateChat(pubKey) { Global.changeAppSectionBySectionType(Constants.appSection.chat) - root.contactsModule.switchToOrCreateOneToOneChat(pubKey) + d.contactsModuleInst.switchToOrCreateOneToOneChat(pubKey) } function unblockContact(pubKey) { - root.contactsModule.unblockContact(pubKey) + d.contactsModuleInst.unblockContact(pubKey) } function blockContact(pubKey) { - root.contactsModule.blockContact(pubKey) + d.contactsModuleInst.blockContact(pubKey) } function removeContact(pubKey) { - root.contactsModule.removeContact(pubKey) + d.contactsModuleInst.removeContact(pubKey) } function changeContactNickname(pubKey, nickname, displayName, isEdit) { - root.contactsModule.changeContactNickname(pubKey, nickname) + d.contactsModuleInst.changeContactNickname(pubKey, nickname) let message = "" if (nickname === "") { // removed nickname @@ -91,37 +102,37 @@ QtObject { } function sendContactRequest(pubKey, message) { - root.contactsModule.sendContactRequest(pubKey, message) + d.contactsModuleInst.sendContactRequest(pubKey, message) Global.displaySuccessToastMessage(qsTr("Contact request sent")) } function acceptContactRequest(pubKey, contactRequestId) { - root.contactsModule.acceptContactRequest(pubKey, contactRequestId) + d.contactsModuleInst.acceptContactRequest(pubKey, contactRequestId) } function dismissContactRequest(pubKey, contactRequestId) { - root.contactsModule.dismissContactRequest(pubKey, contactRequestId) + d.contactsModuleInst.dismissContactRequest(pubKey, contactRequestId) } function getLatestContactRequestForContactAsJson(pubKey) { - let resp = root.contactsModule.getLatestContactRequestForContactAsJson(pubKey) + let resp = d.contactsModuleInst.getLatestContactRequestForContactAsJson(pubKey) return JSON.parse(resp) } function markAsTrusted(pubKey) { - root.contactsModule.markAsTrusted(pubKey) + d.contactsModuleInst.markAsTrusted(pubKey) } function markUntrustworthy(pubKey) { - root.contactsModule.markUntrustworthy(pubKey) + d.contactsModuleInst.markUntrustworthy(pubKey) } function removeTrustStatus(pubKey) { - root.contactsModule.removeTrustStatus(pubKey) + d.contactsModuleInst.removeTrustStatus(pubKey) } function requestContactInfo(publicKey) { - root.contactsModule.requestContactInfo(publicKey) + d.contactsModuleInst.requestContactInfo(publicKey) } function getContactPublicKeyByAddress(address) { @@ -129,6 +140,6 @@ QtObject { } function getLinkToProfile(publicKey) { - return root.contactsModule.shareUserUrlWithData(publicKey) + return d.contactsModuleInst.shareUserUrlWithData(publicKey) } } diff --git a/ui/app/AppLayouts/Profile/stores/ProfileSectionStore.qml b/ui/app/AppLayouts/Profile/stores/ProfileSectionStore.qml index e2a312eea1..4e2be3b249 100644 --- a/ui/app/AppLayouts/Profile/stores/ProfileSectionStore.qml +++ b/ui/app/AppLayouts/Profile/stores/ProfileSectionStore.qml @@ -20,9 +20,7 @@ QtObject { readonly property bool fetchingUpdate: aboutModuleInst.fetching - property ContactsStore contactsStore: ContactsStore { - contactsModule: profileSectionModuleInst.contactsModule - } + property ContactsStore contactsStore: ContactsStore {} property AdvancedStore advancedStore: AdvancedStore { walletModule: profileSectionModuleInst.walletModule