2021-12-06 21:10:54 +00:00
pragma Singleton
2022-10-20 15:12:38 +00:00
import QtQuick 2.14
2022-03-08 18:49:33 +00:00
import AppLayouts . Chat . popups 1.0
2021-12-06 21:10:54 +00:00
2022-09-16 19:25:10 +00:00
import shared . popups 1.0
Item {
2021-12-07 20:33:12 +00:00
id: root
2021-12-21 09:26:13 +00:00
2021-12-08 21:20:43 +00:00
property var applicationWindow
2022-02-28 20:14:04 +00:00
property var appMain
2022-10-06 15:47:55 +00:00
property var dragArea
2021-12-08 21:20:43 +00:00
property bool popupOpened: false
2022-02-25 13:32:46 +00:00
property int settingsSubsection: Constants . settingsSubsection . profile
2021-12-07 20:33:12 +00:00
2022-10-20 15:12:38 +00:00
property var globalUtilsInst: typeof globalUtils !== "undefined" ? globalUtils : null
2022-01-11 23:16:17 +00:00
property var mainModuleInst
2022-03-04 21:33:48 +00:00
property var privacyModuleInst
2022-05-10 16:04:25 +00:00
property var toastMessage
property var pinnedMessagesPopup
property var communityProfilePopup
2021-12-08 21:20:43 +00:00
property bool profilePopupOpened: false
2022-07-26 14:23:45 +00:00
property bool activityCenterPopupOpened: false
2022-05-10 16:04:25 +00:00
property var sendMessageSound
property var notificationSound
property var errorSound
2022-02-01 13:10:24 +00:00
signal openImagePopup ( var image , var contextMenu )
2021-12-06 21:10:54 +00:00
signal openLinkInBrowser ( string link )
signal openChooseBrowserPopup ( string link )
2022-03-03 21:00:52 +00:00
signal openDownloadModalRequested ( bool available , string version , string url )
2021-12-09 13:28:02 +00:00
signal settingsLoaded ( )
2021-12-30 12:39:47 +00:00
signal openBackUpSeedPopup ( )
2022-05-13 15:27:26 +00:00
signal openCreateChatView ( )
signal closeCreateChatView ( )
2021-12-09 13:28:02 +00:00
2022-09-27 21:26:26 +00:00
signal openProfilePopupRequested ( string publicKey , var parentPopup )
signal openNicknamePopupRequested ( string publicKey , string nickname , string subtitle )
signal nickNameChanged ( string publicKey , string nickname )
signal blockContactRequested ( string publicKey , string contactName )
signal contactBlocked ( string publicKey )
signal unblockContactRequested ( string publicKey , string contactName )
signal contactUnblocked ( string publicKey )
2022-02-04 08:43:55 +00:00
signal openChangeProfilePicPopup ( )
2022-05-05 10:28:54 +00:00
signal displayToastMessage ( string title , string subTitle , string icon , bool loading , int ephNotifType , string url )
2022-06-28 18:11:18 +00:00
signal openEditDisplayNamePopup ( )
2022-07-26 14:23:45 +00:00
signal openActivityCenterPopupRequested
2021-12-08 21:20:43 +00:00
2022-09-16 19:25:10 +00:00
function openContactRequestPopup ( publicKey ) {
const contactDetails = Utils . getContactDetailsAsJson ( publicKey ) ;
return openPopup ( sendContactRequestPopupComponent , {
userPublicKey: publicKey ,
userDisplayName: contactDetails . displayName ,
userIcon: contactDetails . largeImage ,
2022-09-27 21:26:26 +00:00
userIsEnsVerified: contactDetails . ensVerified
2022-09-16 19:25:10 +00:00
} )
}
2022-09-28 21:07:18 +00:00
function openInviteFriendsToCommunityPopup ( community , communitySectionModule ) {
return openPopup ( inviteFriendsToCommunityPopup , {
community ,
communitySectionModule
} )
}
2022-09-27 21:26:26 +00:00
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" )
} )
}
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 )
}
}
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 )
}
}
function openProfilePopup ( publicKey , parentPopup ) {
openProfilePopupRequested ( publicKey , parentPopup )
2021-12-09 13:28:02 +00:00
}
2021-12-07 20:33:12 +00:00
2022-07-26 14:23:45 +00:00
function openActivityCenterPopup ( ) {
openActivityCenterPopupRequested ( )
}
2021-12-07 20:33:12 +00:00
function openPopup ( popupComponent , params = { } ) {
2022-04-11 11:39:15 +00:00
const popup = popupComponent . createObject ( root . appMain , params ) ;
popup . open ( ) ;
return popup ;
2021-12-07 20:33:12 +00:00
}
2021-12-06 21:10:54 +00:00
2022-03-03 21:00:52 +00:00
function openDownloadModal ( available , version , url ) {
openDownloadModalRequested ( available , version , url ) ;
2021-12-21 09:26:13 +00:00
}
2022-02-25 13:32:46 +00:00
function changeAppSectionBySectionType ( sectionType , subsection = 0 ) {
2022-01-11 23:16:17 +00:00
if ( ! root . mainModuleInst )
return
2021-12-06 21:10:54 +00:00
mainModuleInst . setActiveSectionBySectionType ( sectionType )
2022-02-25 13:32:46 +00:00
if ( sectionType === Constants . appSection . profile ) {
settingsSubsection = subsection ;
2021-12-08 21:20:43 +00:00
}
}
2022-09-28 10:50:15 +00:00
function setNthEnabledSectionActive ( nthSection ) {
if ( ! root . mainModuleInst )
return
mainModuleInst . setNthEnabledSectionActive ( nthSection )
}
2021-12-08 21:20:43 +00:00
function getProfileImage ( pubkey , isCurrentUser , useLargeImage ) {
if ( isCurrentUser || ( isCurrentUser === undefined && pubkey === userProfile . pubKey ) ) {
return userProfile . icon ;
}
2022-01-05 15:50:03 +00:00
let contactDetails = Utils . getContactDetailsAsJson ( pubkey )
2021-12-31 12:29:51 +00:00
return contactDetails . displayIcon
2021-12-06 21:10:54 +00:00
}
function openLink ( link ) {
2022-08-30 14:49:12 +00:00
// Qt sometimes inserts random HTML tags; and this will break on invalid URL inside QDesktopServices::openUrl(link)
2022-10-20 15:12:38 +00:00
link = globalUtilsInst . plainText ( link ) ;
2021-12-06 21:10:54 +00:00
if ( localAccountSensitiveSettings . showBrowserSelector ) {
openChooseBrowserPopup ( link ) ;
} else {
if ( localAccountSensitiveSettings . openLinksInStatus ) {
changeAppSectionBySectionType ( Constants . appSection . browser ) ;
openLinkInBrowser ( link ) ;
} else {
Qt . openUrlExternally ( link ) ;
}
}
}
function playErrorSound ( ) {
2022-01-11 23:16:17 +00:00
if ( errorSound )
errorSound . play ( ) ;
2021-12-06 21:10:54 +00:00
}
2021-12-09 13:28:02 +00:00
2022-09-16 19:25:10 +00:00
Component {
id: sendContactRequestPopupComponent
2022-09-28 21:07:18 +00:00
2022-09-16 19:25:10 +00:00
SendContactRequestModal {
anchors.centerIn: parent
onAccepted: appMain . rootStore . profileSectionStore . contactsStore . sendContactRequest ( userPublicKey , message )
onClosed: destroy ( )
}
}
2022-09-28 21:07:18 +00:00
Component {
id: inviteFriendsToCommunityPopup
InviteFriendsToCommunityPopup {
anchors.centerIn: parent
rootStore: appMain . rootStore
contactsStore: appMain . rootStore . contactStore
2022-09-27 21:26:26 +00:00
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 )
2022-09-28 21:07:18 +00:00
}
2022-09-27 21:26:26 +00:00
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 ( )
2022-09-28 21:07:18 +00:00
}
}
2022-02-01 13:10:24 +00:00
}