fix(Global): Popup components moved from Global.qml to dedicated non-singleton component

Closes: #7992
This commit is contained in:
Michał Cieślak 2022-10-21 15:37:39 +02:00 committed by Michał
parent 080bc44971
commit 57e80255bf
6 changed files with 185 additions and 141 deletions

View File

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

View File

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

150
ui/app/mainui/Popups.qml Normal file
View File

@ -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<Component> _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()
}
}
]
}

View File

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

View File

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

View File

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