status-desktop/ui/app/AppLayouts/Profile/stores/ContactsStore.qml

222 lines
8.3 KiB
QML
Raw Normal View History

import QtQuick 2.13
import utils 1.0
import StatusQ 0.1
QtObject {
id: root
property var contactsModule
property var globalUtilsInst: globalUtils
property var mainModuleInst: Global.appIsReady? mainModule : null
property string myPublicKey: userProfile.pubKey
// contactsModel holds all available contacts
property var contactsModel: contactsModule.contactsModel
property var myContactsModel: contactsModule.myMutualContactsModel
property var blockedContactsModel: contactsModule.blockedContactsModel
property var receivedContactRequestsModel: contactsModule.receivedContactRequestsModel
property var sentContactRequestsModel: contactsModule.sentContactRequestsModel
readonly property var showcasePublicKey: contactsModule.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 bool isShowcaseForAContactLoading: contactsModule.showcaseForAContactLoading
// Support models for showcase for a contact with showcasePublicKey
readonly property var showcaseCollectiblesModel: contactsModule.showcaseCollectiblesModel
// Sets showcasePublicKey and updates showcase models with corresponding data
function requestProfileShowcase(publicKey) {
root.contactsModule.requestProfileShowcase(publicKey)
}
// Temporary commented until we provide appropriate flags on the `status-go` side to cover all sections.
// property var receivedButRejectedContactRequestsModel: contactsModule.receivedButRejectedContactRequestsModel
// property var sentButRejectedContactRequestsModel: contactsModule.sentButRejectedContactRequestsModel
function resolveENS(value) {
root.mainModuleInst.resolveENS(value, "")
}
function generateAlias(pubKey) {
return root.globalUtilsInst.generateAlias(pubKey)
}
function isMyMutualContact(pubKey) {
return root.contactsModule.isMyMutualContact(pubKey)
}
function isBlockedContact(pubKey) {
return root.contactsModule.isBlockedContact(pubKey)
}
function hasPendingContactRequest(pubKey) {
return root.contactsModule.hasPendingContactRequest(pubKey)
}
function joinPrivateChat(pubKey) {
Global.changeAppSectionBySectionType(Constants.appSection.chat)
root.contactsModule.switchToOrCreateOneToOneChat(pubKey)
}
function unblockContact(pubKey) {
root.contactsModule.unblockContact(pubKey)
}
function blockContact(pubKey) {
root.contactsModule.blockContact(pubKey)
}
function removeContact(pubKey) {
root.contactsModule.removeContact(pubKey)
}
function changeContactNickname(pubKey, nickname, displayName, isEdit) {
root.contactsModule.changeContactNickname(pubKey, nickname)
let message = ""
if (nickname === "") { // removed nickname
message = qsTr("Nickname for %1 removed").arg(displayName)
} else {
if (isEdit)
message = qsTr("Nickname for %1 changed").arg(displayName) // changed nickname
else
message = qsTr("Nickname for %1 added").arg(displayName) // added a new nickname
}
if (!!message) {
Global.displaySuccessToastMessage(message)
}
}
function sendContactRequest(pubKey, message) {
root.contactsModule.sendContactRequest(pubKey, message)
Global.displaySuccessToastMessage(qsTr("Contact request sent"))
}
function acceptContactRequest(pubKey, contactRequestId) {
root.contactsModule.acceptContactRequest(pubKey, contactRequestId)
}
function dismissContactRequest(pubKey, contactRequestId) {
root.contactsModule.dismissContactRequest(pubKey, contactRequestId)
}
function getLatestContactRequestForContactAsJson(pubKey) {
let resp = root.contactsModule.getLatestContactRequestForContactAsJson(pubKey)
return JSON.parse(resp)
}
function markAsTrusted(pubKey) {
root.contactsModule.markAsTrusted(pubKey)
}
function markUntrustworthy(pubKey) {
root.contactsModule.markUntrustworthy(pubKey)
}
function removeTrustStatus(pubKey) {
root.contactsModule.removeTrustStatus(pubKey)
}
function removeTrustVerificationStatus(pubKey) {
root.contactsModule.removeTrustVerificationStatus(pubKey)
}
function sendVerificationRequest(pubKey, challenge) {
root.contactsModule.sendVerificationRequest(pubKey, challenge);
Global.displaySuccessToastMessage(qsTr("ID verification request sent"))
}
function cancelVerificationRequest(pubKey) {
root.contactsModule.cancelVerificationRequest(pubKey);
Global.displaySuccessToastMessage(qsTr("ID verification request cancelled"))
}
function declineVerificationRequest(pubKey) {
root.contactsModule.declineVerificationRequest(pubKey);
}
function acceptVerificationRequest(pubKey, response) {
root.contactsModule.acceptVerificationRequest(pubKey, response);
}
function getVerificationDetailsFromAsJson(pubKey) {
let resp = root.contactsModule.getVerificationDetailsFromAsJson(pubKey);
return JSON.parse(resp);
}
function getSentVerificationDetailsAsJson(pubKey) {
let resp = root.contactsModule.getSentVerificationDetailsAsJson(pubKey);
return JSON.parse(resp);
}
function verifiedTrusted(pubKey) {
root.contactsModule.verifiedTrusted(pubKey);
}
function verifiedUntrustworthy(pubKey) {
root.contactsModule.verifiedUntrustworthy(pubKey);
}
function requestContactInfo(publicKey) {
root.contactsModule.requestContactInfo(publicKey)
}
function getContactPublicKeyByAddress(address) {
return "" // TODO retrive contact public key from address
}
function getLinkToProfile(publicKey) {
return root.contactsModule.shareUserUrlWithData(publicKey)
}
function getProfileContext(publicKey, isBridgedAccount = false) {
refactor ProfileContextMenu to make it a functional component refactor ProfileContextMenu to make it a functional component refactor ProfileContextMenu to make it a functional component refactor ProfileContextMenu to make it a functional component This refactor ProfileContextMenu to make it a functional component by: refactored out direct calls to backend, and passing backend data structures and moved this logic to the callers, also refactored common calls between the callers common types of context menus have been extracted to their sub components which removes a lot of logic too and makes the behaviour very clear user verification workflow (which was already disabled) has been removed refactor: use signals and call singletons on the parent instead remove unused code for now from profile context menu refactor profile context menu into two components; add property to storybook extract blocked profile context menu and self profile context menu use profileType instead of individual bools refactor to pass trustStatus as an argument make contact type a parameter remove unnecessary method from RegularProfileContextMenu add ensVerified property to ProfileContextMenu components add onlineStatus property to ProfileContextMenu components move ProfileContextMenu storybook controls to the right sidebar move contactDetails logic up from the view add local nickname property to ProfileContextMenu components fix issue with missing signal; fix logs in storybook use constant for profileType instead of string refactor common code into a single method refactor getProfileContext remove references to contactDetails which are not longer needed remove unnecessary comments fix bridged constant refactor into a single ProfileContextMenu component refactor into a single ProfileContextMenu component refactor into a single ProfileContextMenu component simplify imports remove unused store field move methods from utils to contacts store remove onClosed signal remove unused param rename ProfileContextMenu variables simplify signals in ProfileContextMenu remove ; refactor: do early return simplify ifs move ProfileContextMenu to its own storybook page fix wrong params fix profile context menu separator add missing signals to profile context menu on the members tab panel
2024-09-06 15:55:44 +00:00
const contactDetails = Utils.getContactDetailsAsJson(publicKey, true, true)
if (!contactDetails)
return {
profileType: getProfileType(publicKey, isBridgedAccount, false),
refactor ProfileContextMenu to make it a functional component refactor ProfileContextMenu to make it a functional component refactor ProfileContextMenu to make it a functional component refactor ProfileContextMenu to make it a functional component This refactor ProfileContextMenu to make it a functional component by: refactored out direct calls to backend, and passing backend data structures and moved this logic to the callers, also refactored common calls between the callers common types of context menus have been extracted to their sub components which removes a lot of logic too and makes the behaviour very clear user verification workflow (which was already disabled) has been removed refactor: use signals and call singletons on the parent instead remove unused code for now from profile context menu refactor profile context menu into two components; add property to storybook extract blocked profile context menu and self profile context menu use profileType instead of individual bools refactor to pass trustStatus as an argument make contact type a parameter remove unnecessary method from RegularProfileContextMenu add ensVerified property to ProfileContextMenu components add onlineStatus property to ProfileContextMenu components move ProfileContextMenu storybook controls to the right sidebar move contactDetails logic up from the view add local nickname property to ProfileContextMenu components fix issue with missing signal; fix logs in storybook use constant for profileType instead of string refactor common code into a single method refactor getProfileContext remove references to contactDetails which are not longer needed remove unnecessary comments fix bridged constant refactor into a single ProfileContextMenu component refactor into a single ProfileContextMenu component refactor into a single ProfileContextMenu component simplify imports remove unused store field move methods from utils to contacts store remove onClosed signal remove unused param rename ProfileContextMenu variables simplify signals in ProfileContextMenu remove ; refactor: do early return simplify ifs move ProfileContextMenu to its own storybook page fix wrong params fix profile context menu separator add missing signals to profile context menu on the members tab panel
2024-09-06 15:55:44 +00:00
trustStatus: Constants.trustStatus.unknown,
contactType: getContactType(Constants.ContactRequestState.None, false),
ensVerified: false,
onlineStatus: Constants.onlineStatus.unknown,
hasLocalNickname: false
}
const isBlocked = contactDetails.isBlocked
const profileType = getProfileType(publicKey, isBridgedAccount, isBlocked)
refactor ProfileContextMenu to make it a functional component refactor ProfileContextMenu to make it a functional component refactor ProfileContextMenu to make it a functional component refactor ProfileContextMenu to make it a functional component This refactor ProfileContextMenu to make it a functional component by: refactored out direct calls to backend, and passing backend data structures and moved this logic to the callers, also refactored common calls between the callers common types of context menus have been extracted to their sub components which removes a lot of logic too and makes the behaviour very clear user verification workflow (which was already disabled) has been removed refactor: use signals and call singletons on the parent instead remove unused code for now from profile context menu refactor profile context menu into two components; add property to storybook extract blocked profile context menu and self profile context menu use profileType instead of individual bools refactor to pass trustStatus as an argument make contact type a parameter remove unnecessary method from RegularProfileContextMenu add ensVerified property to ProfileContextMenu components add onlineStatus property to ProfileContextMenu components move ProfileContextMenu storybook controls to the right sidebar move contactDetails logic up from the view add local nickname property to ProfileContextMenu components fix issue with missing signal; fix logs in storybook use constant for profileType instead of string refactor common code into a single method refactor getProfileContext remove references to contactDetails which are not longer needed remove unnecessary comments fix bridged constant refactor into a single ProfileContextMenu component refactor into a single ProfileContextMenu component refactor into a single ProfileContextMenu component simplify imports remove unused store field move methods from utils to contacts store remove onClosed signal remove unused param rename ProfileContextMenu variables simplify signals in ProfileContextMenu remove ; refactor: do early return simplify ifs move ProfileContextMenu to its own storybook page fix wrong params fix profile context menu separator add missing signals to profile context menu on the members tab panel
2024-09-06 15:55:44 +00:00
const contactType = getContactType(contactDetails.contactRequestState, contactDetails.isContact)
const trustStatus = contactDetails.trustStatus
const ensVerified = contactDetails.ensVerified
const onlineStatus = contactDetails.onlineStatus
const hasLocalNickname = !!contactDetails.localNickname
return { profileType, trustStatus, contactType, ensVerified, onlineStatus, hasLocalNickname }
}
function getProfileType(publicKey, isBridgedAccount, isBlocked) {
if (publicKey === root.myPublicKey) return Constants.profileType.self
refactor ProfileContextMenu to make it a functional component refactor ProfileContextMenu to make it a functional component refactor ProfileContextMenu to make it a functional component refactor ProfileContextMenu to make it a functional component This refactor ProfileContextMenu to make it a functional component by: refactored out direct calls to backend, and passing backend data structures and moved this logic to the callers, also refactored common calls between the callers common types of context menus have been extracted to their sub components which removes a lot of logic too and makes the behaviour very clear user verification workflow (which was already disabled) has been removed refactor: use signals and call singletons on the parent instead remove unused code for now from profile context menu refactor profile context menu into two components; add property to storybook extract blocked profile context menu and self profile context menu use profileType instead of individual bools refactor to pass trustStatus as an argument make contact type a parameter remove unnecessary method from RegularProfileContextMenu add ensVerified property to ProfileContextMenu components add onlineStatus property to ProfileContextMenu components move ProfileContextMenu storybook controls to the right sidebar move contactDetails logic up from the view add local nickname property to ProfileContextMenu components fix issue with missing signal; fix logs in storybook use constant for profileType instead of string refactor common code into a single method refactor getProfileContext remove references to contactDetails which are not longer needed remove unnecessary comments fix bridged constant refactor into a single ProfileContextMenu component refactor into a single ProfileContextMenu component refactor into a single ProfileContextMenu component simplify imports remove unused store field move methods from utils to contacts store remove onClosed signal remove unused param rename ProfileContextMenu variables simplify signals in ProfileContextMenu remove ; refactor: do early return simplify ifs move ProfileContextMenu to its own storybook page fix wrong params fix profile context menu separator add missing signals to profile context menu on the members tab panel
2024-09-06 15:55:44 +00:00
if (isBridgedAccount) return Constants.profileType.bridged
if (isBlocked) return Constants.profileType.blocked
return Constants.profileType.regular
}
function getContactType(contactRequestState, isContact) {
switch (contactRequestState) {
case Constants.ContactRequestState.Received:
return Constants.contactType.contactRequestReceived
case Constants.ContactRequestState.Sent:
return Constants.contactType.contactRequestSent
default:
return isContact ? Constants.contactType.contact : Constants.contactType.nonContact
}
}
}