2021-12-31 12:29:51 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import utils 1.0
|
|
|
|
|
2024-06-03 08:56:25 +00:00
|
|
|
import StatusQ 0.1
|
|
|
|
|
2021-12-31 12:29:51 +00:00
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property var contactsModule
|
|
|
|
|
|
|
|
property var globalUtilsInst: globalUtils
|
2023-02-14 09:20:53 +00:00
|
|
|
property var mainModuleInst: Global.appIsReady? mainModule : null
|
2021-12-31 12:29:51 +00:00
|
|
|
|
2023-02-14 09:20:53 +00:00
|
|
|
property string myPublicKey: !!Global.userProfile? Global.userProfile.pubKey : ""
|
2021-12-31 12:29:51 +00:00
|
|
|
|
2024-06-03 08:56:25 +00:00
|
|
|
// contactsModel holds all available contacts
|
|
|
|
property var contactsModel: contactsModule.contactsModel
|
2022-03-24 20:55:22 +00:00
|
|
|
property var myContactsModel: contactsModule.myMutualContactsModel
|
|
|
|
property var blockedContactsModel: contactsModule.blockedContactsModel
|
|
|
|
property var receivedContactRequestsModel: contactsModule.receivedContactRequestsModel
|
|
|
|
property var sentContactRequestsModel: contactsModule.sentContactRequestsModel
|
2022-04-08 20:17:16 +00:00
|
|
|
|
2024-03-29 11:43:49 +00:00
|
|
|
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
|
|
|
|
|
2024-04-07 22:00:16 +00:00
|
|
|
readonly property bool isShowcaseForAContactLoading: contactsModule.showcaseForAContactLoading
|
|
|
|
|
2024-03-29 11:43:49 +00:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2022-04-08 20:17:16 +00:00
|
|
|
// 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
|
2022-03-15 15:55:18 +00:00
|
|
|
|
2022-01-04 12:06:05 +00:00
|
|
|
function resolveENS(value) {
|
|
|
|
root.mainModuleInst.resolveENS(value, "")
|
2021-12-31 12:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function generateAlias(pubKey) {
|
2024-03-29 11:43:49 +00:00
|
|
|
return root.globalUtilsInst.generateAlias(pubKey)
|
2021-12-31 12:29:51 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 11:33:30 +00:00
|
|
|
function isMyMutualContact(pubKey) {
|
2024-03-29 11:43:49 +00:00
|
|
|
return root.contactsModule.isMyMutualContact(pubKey)
|
2022-03-25 11:33:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-20 14:48:38 +00:00
|
|
|
function isBlockedContact(pubKey) {
|
2024-03-29 11:43:49 +00:00
|
|
|
return root.contactsModule.isBlockedContact(pubKey)
|
2022-06-20 14:48:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function hasPendingContactRequest(pubKey) {
|
2024-03-29 11:43:49 +00:00
|
|
|
return root.contactsModule.hasPendingContactRequest(pubKey)
|
2022-06-20 14:48:38 +00:00
|
|
|
}
|
|
|
|
|
2021-12-31 12:29:51 +00:00
|
|
|
function joinPrivateChat(pubKey) {
|
|
|
|
Global.changeAppSectionBySectionType(Constants.appSection.chat)
|
2022-05-17 08:06:21 +00:00
|
|
|
root.contactsModule.switchToOrCreateOneToOneChat(pubKey)
|
2021-12-31 12:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function unblockContact(pubKey) {
|
|
|
|
root.contactsModule.unblockContact(pubKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
function blockContact(pubKey) {
|
|
|
|
root.contactsModule.blockContact(pubKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeContact(pubKey) {
|
|
|
|
root.contactsModule.removeContact(pubKey)
|
|
|
|
}
|
|
|
|
|
2024-02-14 12:52:54 +00:00
|
|
|
function changeContactNickname(pubKey, nickname, displayName, isEdit) {
|
2021-12-31 12:29:51 +00:00
|
|
|
root.contactsModule.changeContactNickname(pubKey, nickname)
|
2024-02-14 12:52:54 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2021-12-31 12:29:51 +00:00
|
|
|
}
|
2022-05-27 08:57:18 +00:00
|
|
|
|
|
|
|
function sendContactRequest(pubKey, message) {
|
|
|
|
root.contactsModule.sendContactRequest(pubKey, message)
|
2024-02-16 11:56:29 +00:00
|
|
|
Global.displaySuccessToastMessage(qsTr("Contact request sent"))
|
2022-05-27 08:57:18 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 16:27:56 +00:00
|
|
|
function acceptContactRequest(pubKey, contactRequestId) {
|
|
|
|
root.contactsModule.acceptContactRequest(pubKey, contactRequestId)
|
2022-03-15 15:55:18 +00:00
|
|
|
}
|
|
|
|
|
2023-04-03 16:27:56 +00:00
|
|
|
function dismissContactRequest(pubKey, contactRequestId) {
|
|
|
|
root.contactsModule.dismissContactRequest(pubKey, contactRequestId)
|
2022-03-15 15:55:18 +00:00
|
|
|
}
|
|
|
|
|
2024-02-29 09:49:37 +00:00
|
|
|
function getLatestContactRequestForContactAsJson(pubKey) {
|
|
|
|
let resp = root.contactsModule.getLatestContactRequestForContactAsJson(pubKey)
|
|
|
|
return JSON.parse(resp)
|
|
|
|
}
|
|
|
|
|
2024-02-28 13:50:40 +00:00
|
|
|
function markAsTrusted(pubKey) {
|
|
|
|
root.contactsModule.markAsTrusted(pubKey)
|
|
|
|
}
|
|
|
|
|
2022-06-28 18:11:18 +00:00
|
|
|
function markUntrustworthy(pubKey) {
|
|
|
|
root.contactsModule.markUntrustworthy(pubKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeTrustStatus(pubKey) {
|
|
|
|
root.contactsModule.removeTrustStatus(pubKey)
|
|
|
|
}
|
|
|
|
|
2024-04-18 16:09:27 +00:00
|
|
|
function removeTrustVerificationStatus(pubKey) {
|
|
|
|
root.contactsModule.removeTrustVerificationStatus(pubKey)
|
|
|
|
}
|
|
|
|
|
2022-06-28 18:11:18 +00:00
|
|
|
function sendVerificationRequest(pubKey, challenge) {
|
|
|
|
root.contactsModule.sendVerificationRequest(pubKey, challenge);
|
2024-02-16 11:56:29 +00:00
|
|
|
Global.displaySuccessToastMessage(qsTr("ID verification request sent"))
|
2022-06-28 18:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function cancelVerificationRequest(pubKey) {
|
|
|
|
root.contactsModule.cancelVerificationRequest(pubKey);
|
2024-02-16 17:34:09 +00:00
|
|
|
Global.displaySuccessToastMessage(qsTr("ID verification request cancelled"))
|
2022-06-28 18:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2023-04-06 07:56:50 +00:00
|
|
|
|
|
|
|
function requestContactInfo(publicKey) {
|
|
|
|
root.contactsModule.requestContactInfo(publicKey)
|
|
|
|
}
|
2023-05-22 10:16:39 +00:00
|
|
|
|
|
|
|
function getContactPublicKeyByAddress(address) {
|
|
|
|
return "" // TODO retrive contact public key from address
|
|
|
|
}
|
2023-07-06 11:26:30 +00:00
|
|
|
|
|
|
|
function getLinkToProfile(publicKey) {
|
|
|
|
return root.contactsModule.shareUserUrlWithData(publicKey)
|
|
|
|
}
|
2024-10-15 09:58:09 +00:00
|
|
|
function getProfileContext(publicKey, isBridgedAccount = false) {
|
2024-09-06 15:55:44 +00:00
|
|
|
const contactDetails = Utils.getContactDetailsAsJson(publicKey, true, true)
|
|
|
|
if (!contactDetails)
|
|
|
|
return {
|
2024-10-15 09:58:09 +00:00
|
|
|
profileType: getProfileType(publicKey, isBridgedAccount, false),
|
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
|
2024-10-15 09:58:09 +00:00
|
|
|
const profileType = getProfileType(publicKey, isBridgedAccount, isBlocked)
|
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 }
|
|
|
|
}
|
|
|
|
|
2024-10-15 09:58:09 +00:00
|
|
|
function getProfileType(publicKey, isBridgedAccount, isBlocked) {
|
|
|
|
if (publicKey === root.myPublicKey) return Constants.profileType.self
|
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
|
|
|
|
}
|
|
|
|
}
|
2021-12-31 12:29:51 +00:00
|
|
|
}
|