diff --git a/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml b/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml index 8519289720..08ee56dbcb 100644 --- a/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml +++ b/ui/app/AppLayouts/Chat/views/MembersSelectorView.qml @@ -106,8 +106,8 @@ MembersSelectorBase { } if (root.model.count === 0) { - const popup = Global.openContactRequestPopup(contactDetails.publicKey) - popup.closed.connect(root.rejected) + Global.openContactRequestPopup(contactDetails.publicKey, + popup => popup.closed.connect(root.rejected)) return } } diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index a7c299b013..2977434481 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -73,6 +73,18 @@ Item { } } + Popups { + rootStore: appMain.rootStore + + Component.onCompleted: { + Global.openSendIDRequestPopup.connect(openSendIDRequestPopup) + Global.openOutgoingIDRequestPopup.connect(openOutgoingIDRequestPopup) + Global.openIncomingIDRequestPopup.connect(openIncomingIDRequestPopup) + Global.openInviteFriendsToCommunityPopup.connect(openInviteFriendsToCommunityPopup) + Global.openContactRequestPopup.connect(openContactRequestPopup) + } + } + Connections { target: Global onOpenLinkInBrowser: { diff --git a/ui/app/mainui/Popups.qml b/ui/app/mainui/Popups.qml new file mode 100644 index 0000000000..7722d2f553 --- /dev/null +++ b/ui/app/mainui/Popups.qml @@ -0,0 +1,150 @@ +import QtQuick 2.14 + +import AppLayouts.Chat.popups 1.0 +import shared.popups 1.0 + +import utils 1.0 + +QtObject { + id: root + + /* required */ property var rootStore + + function openSendIDRequestPopup(publicKey, cb) { + const contactDetails = Utils.getContactDetailsAsJson(publicKey) + const popup = Global.openPopup(sendIDRequestPopupComponent, { + userPublicKey: publicKey, + userDisplayName: contactDetails.displayName, + userIcon: contactDetails.largeImage, + userIsEnsVerified: contactDetails.ensVerified, + "header.title": qsTr("Verify %1's Identity").arg(contactDetails.displayName), + challengeText: qsTr("Ask a question that only the real %1 will be able to answer e.g. a question about a shared experience, or ask %1 to enter a code or phrase you have sent to them via a different communication channel (phone, post, etc...).").arg(contactDetails.displayName), + buttonText: qsTr("Send verification request") + }) + if (cb) + cb(popup) + } + + function openOutgoingIDRequestPopup(publicKey, cb) { + try { + const verificationDetails = root.rootStore.profileSectionStore.contactsStore.getSentVerificationDetailsAsJson(publicKey) + const popupProperties = { + userPublicKey: publicKey, + verificationStatus: verificationDetails.requestStatus, + verificationChallenge: verificationDetails.challenge, + verificationResponse: verificationDetails.response, + verificationResponseDisplayName: verificationDetails.displayName, + verificationResponseIcon: verificationDetails.icon, + verificationRequestedAt: verificationDetails.requestedAt, + verificationRepliedAt: verificationDetails.repliedAt + } + const popup = Global.openPopup(contactOutgoingVerificationRequestPopupComponent, popupProperties) + if (cb) + cb(popup) + } catch (e) { + console.error("Error getting or parsing verification data", e) + } + } + + function openIncomingIDRequestPopup(publicKey, cb) { + try { + const request = root.rootStore.profileSectionStore.contactsStore.getVerificationDetailsFromAsJson(publicKey) + const popupProperties = { + senderPublicKey: request.from, + senderDisplayName: request.displayName, + senderIcon: request.icon, + challengeText: request.challenge, + responseText: request.response, + messageTimestamp: request.requestedAt, + responseTimestamp: request.repliedAt + } + + const popup = Global.openPopup(contactVerificationRequestPopupComponent, popupProperties) + if (cb) + cb(popup) + } catch (e) { + console.error("Error getting or parsing verification data", e) + } + } + + function openInviteFriendsToCommunityPopup(community, communitySectionModule, cb) { + const popup = Global.openPopup(inviteFriendsToCommunityPopup, { community, communitySectionModule }) + if (cb) + cb(popup) + } + + function openContactRequestPopup(publicKey, cb) { + const contactDetails = Utils.getContactDetailsAsJson(publicKey) + const popupProperties = { + userPublicKey: publicKey, + userDisplayName: contactDetails.displayName, + userIcon: contactDetails.largeImage, + userIsEnsVerified: contactDetails.ensVerified + } + + const popup = Global.openPopup(sendContactRequestPopupComponent, popupProperties) + if (cb) + cb(popup) + } + + readonly property list _d: [ + Component { + id: contactVerificationRequestPopupComponent + ContactVerificationRequestPopup { + onResponseSent: { + root.rootStore.profileSectionStore.contactsStore.acceptVerificationRequest(senderPublicKey, response) + } + onVerificationRefused: { + root.rootStore.profileSectionStore.contactsStore.declineVerificationRequest(senderPublicKey) + } + onClosed: destroy() + } + }, + + Component { + id: contactOutgoingVerificationRequestPopupComponent + OutgoingContactVerificationRequestPopup { + onVerificationRequestCanceled: { + root.rootStore.profileSectionStore.contactsStore.cancelVerificationRequest(userPublicKey) + } + onUntrustworthyVerified: { + root.rootStore.profileSectionStore.contactsStore.verifiedUntrustworthy(userPublicKey) + } + onTrustedVerified: { + root.rootStore.profileSectionStore.contactsStore.verifiedTrusted(userPublicKey) + } + onClosed: destroy() + } + }, + + Component { + id: sendIDRequestPopupComponent + SendContactRequestModal { + anchors.centerIn: parent + onAccepted: root.rootStore.profileSectionStore.contactsStore.sendVerificationRequest(userPublicKey, message) + onClosed: destroy() + } + }, + + Component { + id: inviteFriendsToCommunityPopup + + InviteFriendsToCommunityPopup { + anchors.centerIn: parent + rootStore: root.rootStore + contactsStore: root.rootStore.contactStore + onClosed: destroy() + } + }, + + Component { + id: sendContactRequestPopupComponent + + SendContactRequestModal { + anchors.centerIn: parent + onAccepted: root.rootStore.profileSectionStore.contactsStore.sendContactRequest(userPublicKey, message) + onClosed: destroy() + } + } + ] +} diff --git a/ui/imports/Themes/Theme.qml b/ui/imports/Themes/Theme.qml index f73cce6ec1..0032c7b62b 100644 --- a/ui/imports/Themes/Theme.qml +++ b/ui/imports/Themes/Theme.qml @@ -1,5 +1,4 @@ -import QtQuick 2.13 -import utils 1.0 +import QtQuick 2.14 QtObject { readonly property FontLoader baseFont: FontLoader { source: "../../fonts/Inter/Inter-Regular.otf" } diff --git a/ui/imports/shared/views/ProfileDialogView.qml b/ui/imports/shared/views/ProfileDialogView.qml index 428faad3a9..a726e2c28f 100644 --- a/ui/imports/shared/views/ProfileDialogView.qml +++ b/ui/imports/shared/views/ProfileDialogView.qml @@ -152,8 +152,8 @@ Pane { size: StatusButton.Size.Small text: qsTr("Send Contact Request") onClicked: { - let contactRequestPopup = Global.openContactRequestPopup(root.publicKey) - contactRequestPopup.accepted.connect(d.reload) + Global.openContactRequestPopup(root.publicKey, + popup => popup.accepted.connect(d.reload)) } } } @@ -205,8 +205,8 @@ Pane { size: StatusButton.Size.Small text: qsTr("Respond to ID Request") onClicked: { - let idRequestPopup = Global.openIncomingIDRequestPopup(root.publicKey) - idRequestPopup.closed.connect(d.reload) + Global.openIncomingIDRequestPopup(root.publicKey, + popup => popup.closed.connect(d.reload)) } } } @@ -384,8 +384,8 @@ Pane { d.contactDetails.trustStatus === Constants.trustStatus.untrustworthy // we have an action button otherwise onTriggered: { moreMenu.close() - let contactRequestPopup = Global.openContactRequestPopup(root.publicKey) - contactRequestPopup.closed.connect(d.reload) + Global.openContactRequestPopup(root.publicKey, + popup => popup.closed.connect(d.reload)) } } StatusMenuItem { @@ -396,8 +396,8 @@ Pane { !d.isVerificationRequestReceived onTriggered: { moreMenu.close() - let idRequestPopup = Global.openSendIDRequestPopup(root.publicKey) - idRequestPopup.accepted.connect(d.reload) + Global.openSendIDRequestPopup(root.publicKey, + popup => popup.accepted.connect(d.reload)) } } StatusMenuItem { @@ -406,8 +406,8 @@ Pane { enabled: d.isContact && !d.isBlocked && !d.isTrusted && d.isVerificationRequestSent onTriggered: { moreMenu.close() - let idRequestPopup = Global.openOutgoingIDRequestPopup(root.publicKey) - idRequestPopup.closed.connect(d.reload) + Global.openOutgoingIDRequestPopup(root.publicKey, + popup => popup.closed.connect(d.reload)) } } StatusMenuItem { diff --git a/ui/imports/utils/Global.qml b/ui/imports/utils/Global.qml index 801e4cc180..532a87f656 100644 --- a/ui/imports/utils/Global.qml +++ b/ui/imports/utils/Global.qml @@ -1,11 +1,8 @@ pragma Singleton -import QtQuick 2.14 -import AppLayouts.Chat.popups 1.0 +import QtQml 2.14 -import shared.popups 1.0 - -Item { +QtObject { id: root property var applicationWindow @@ -52,70 +49,15 @@ Item { signal openEditDisplayNamePopup() signal openActivityCenterPopupRequested - function openContactRequestPopup(publicKey) { - const contactDetails = Utils.getContactDetailsAsJson(publicKey); - return openPopup(sendContactRequestPopupComponent, { - userPublicKey: publicKey, - userDisplayName: contactDetails.displayName, - userIcon: contactDetails.largeImage, - userIsEnsVerified: contactDetails.ensVerified - }) - } + signal openContactRequestPopup(string publicKey, var cb) - function openInviteFriendsToCommunityPopup(community, communitySectionModule) { - return openPopup(inviteFriendsToCommunityPopup, { - community, - communitySectionModule - }) - } + signal openInviteFriendsToCommunityPopup(var community, var communitySectionModule, var cb) - function openSendIDRequestPopup(publicKey) { - const contactDetails = Utils.getContactDetailsAsJson(publicKey); - return openPopup(sendIDRequestPopupComponent, { - userPublicKey: publicKey, - userDisplayName: contactDetails.displayName, - userIcon: contactDetails.largeImage, - userIsEnsVerified: contactDetails.ensVerified, - "header.title": qsTr("Verify %1's Identity").arg(contactDetails.displayName), - challengeText: qsTr("Ask a question that only the real %1 will be able to answer e.g. a question about a shared experience, or ask %1 to enter a code or phrase you have sent to them via a different communication channel (phone, post, etc...).").arg(contactDetails.displayName), - buttonText: qsTr("Send verification request") - }) - } + signal openSendIDRequestPopup(string publicKey, var cb) - function openIncomingIDRequestPopup(publicKey) { - try { - const request = appMain.rootStore.profileSectionStore.contactsStore.getVerificationDetailsFromAsJson(publicKey) - return openPopup(contactVerificationRequestPopupComponent, { - senderPublicKey: request.from, - senderDisplayName: request.displayName, - senderIcon: request.icon, - challengeText: request.challenge, - responseText: request.response, - messageTimestamp: request.requestedAt, - responseTimestamp: request.repliedAt - }) - } catch (e) { - console.error("Error getting or parsing verification data", e) - } - } + signal openIncomingIDRequestPopup(string publicKey, var cb) - function openOutgoingIDRequestPopup(publicKey) { - try { - const verificationDetails = appMain.rootStore.profileSectionStore.contactsStore.getSentVerificationDetailsAsJson(publicKey) - return openPopup(contactOutgoingVerificationRequestPopupComponent, { - userPublicKey: publicKey, - verificationStatus: verificationDetails.requestStatus, - verificationChallenge: verificationDetails.challenge, - verificationResponse: verificationDetails.response, - verificationResponseDisplayName: verificationDetails.displayName, - verificationResponseIcon: verificationDetails.icon, - verificationRequestedAt: verificationDetails.requestedAt, - verificationRepliedAt: verificationDetails.repliedAt - }) - } catch (e) { - console.error("Error getting or parsing verification data", e) - } - } + signal openOutgoingIDRequestPopup(string publicKey, var cb) function openProfilePopup(publicKey, parentPopup) { openProfilePopupRequested(publicKey, parentPopup) @@ -126,9 +68,9 @@ Item { } function openPopup(popupComponent, params = {}) { - const popup = popupComponent.createObject(root.appMain, params); - popup.open(); - return popup; + const popup = popupComponent.createObject(root.appMain, params) + popup.open() + return popup } function openDownloadModal(available, version, url){ @@ -179,63 +121,4 @@ Item { if(errorSound) errorSound.play(); } - - Component { - id: sendContactRequestPopupComponent - - SendContactRequestModal { - anchors.centerIn: parent - onAccepted: appMain.rootStore.profileSectionStore.contactsStore.sendContactRequest(userPublicKey, message) - onClosed: destroy() - } - } - - Component { - id: inviteFriendsToCommunityPopup - - InviteFriendsToCommunityPopup { - anchors.centerIn: parent - rootStore: appMain.rootStore - contactsStore: appMain.rootStore.contactStore - onClosed: destroy() - } - } - - Component { - id: sendIDRequestPopupComponent - SendContactRequestModal { - anchors.centerIn: parent - onAccepted: appMain.rootStore.profileSectionStore.contactsStore.sendVerificationRequest(userPublicKey, message) - onClosed: destroy() - } - } - - Component { - id: contactVerificationRequestPopupComponent - ContactVerificationRequestPopup { - onResponseSent: { - appMain.rootStore.profileSectionStore.contactsStore.acceptVerificationRequest(senderPublicKey, response) - } - onVerificationRefused: { - appMain.rootStore.profileSectionStore.contactsStore.declineVerificationRequest(senderPublicKey) - } - onClosed: destroy() - } - } - - Component { - id: contactOutgoingVerificationRequestPopupComponent - OutgoingContactVerificationRequestPopup { - onVerificationRequestCanceled: { - appMain.rootStore.profileSectionStore.contactsStore.cancelVerificationRequest(userPublicKey) - } - onUntrustworthyVerified: { - appMain.rootStore.profileSectionStore.contactsStore.verifiedUntrustworthy(userPublicKey) - } - onTrustedVerified: { - appMain.rootStore.profileSectionStore.contactsStore.verifiedTrusted(userPublicKey) - } - onClosed: destroy() - } - } }