status-desktop/ui/imports/shared/popups/ProfilePopup.qml

188 lines
5.5 KiB
QML
Raw Normal View History

2020-06-17 19:18:31 +00:00
import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import QtGraphicalEffects 1.13
import utils 1.0
import shared 1.0
import shared.popups 1.0
import shared.stores 1.0
2022-06-22 12:16:21 +00:00
import shared.views 1.0 as SharedViews
import shared.controls.chat 1.0
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import StatusQ.Popups 0.1
StatusModal {
id: popup
2020-10-02 13:02:56 +00:00
property Popup parentPopup
property var profileStore
property var contactsStore
property string userPublicKey: ""
property string userDisplayName: ""
property string userName: ""
property string userNickname: ""
property string userEnsName: ""
property string userIcon: ""
property bool userIsEnsVerified: false
property bool userIsBlocked: false
property bool isCurrentUser: false
property bool isAddedContact: false
2020-06-17 21:43:26 +00:00
signal contactUnblocked(publicKey: string)
2020-10-02 14:37:51 +00:00
signal contactBlocked(publicKey: string)
function openPopup(publicKey, state = "") {
// All this should be improved more, but for now we leave it like this.
2022-06-22 12:16:21 +00:00
const contactDetails = Utils.getContactDetailsAsJson(publicKey);
userPublicKey = publicKey;
userDisplayName = contactDetails.displayName;
userName = contactDetails.alias;
userNickname = contactDetails.localNickname;
userEnsName = contactDetails.name;
userIcon = contactDetails.displayIcon;
userIsEnsVerified = contactDetails.ensVerified;
userIsBlocked = contactDetails.isBlocked;
isAddedContact = contactDetails.isContact;
isCurrentUser = popup.profileStore.pubkey === publicKey;
2022-06-22 12:16:21 +00:00
showFooter = !isCurrentUser;
popup.open();
if (state == "openNickname") {
nicknamePopup.open();
} else if (state == "contactRequest") {
sendContactRequestModal.open()
} else if (state == "blockUser") {
blockUser();
} else if (state == "unblockUser") {
unblockUser();
}
2020-06-17 21:43:26 +00:00
}
function blockUser() {
2022-06-22 12:16:21 +00:00
profileView.blockContactConfirmationDialog.contactName = userName;
profileView.blockContactConfirmationDialog.contactAddress = userPublicKey;
profileView.blockContactConfirmationDialog.open();
}
function unblockUser() {
2022-06-22 12:16:21 +00:00
profileView.unblockContactConfirmationDialog.contactName = userName;
profileView.unblockContactConfirmationDialog.contactAddress = userPublicKey;
profileView.unblockContactConfirmationDialog.open();
}
header.title: userDisplayName + qsTr("'s Profile")
header.subTitle: userIsEnsVerified ? userName : Utils.getElidedCompressedPk(userPublicKey)
header.subTitleElide: Text.ElideMiddle
2022-06-22 12:16:21 +00:00
padding: 8
QtObject {
id: d
readonly property int contentSpacing: 5
readonly property int contentMargins: 16
}
headerActionButton: StatusFlatRoundButton {
type: StatusFlatRoundButton.Type.Secondary
width: 32
height: 32
icon.width: 20
icon.height: 20
icon.name: "qr"
2022-06-22 12:16:21 +00:00
onClicked: profileView.qrCodePopup.open()
}
2022-06-22 12:16:21 +00:00
SharedViews.ProfileView {
id: profileView
anchors.fill: parent
profileStore: popup.profileStore
contactsStore: popup.contactsStore
userPublicKey: popup.userPublicKey
userDisplayName: popup.userDisplayName
userName: popup.userName
userNickname: popup.userNickname
userEnsName: popup.userEnsName
userIcon: popup.userIcon
userIsEnsVerified: popup.userIsEnsVerified
userIsBlocked: popup.userIsBlocked
isAddedContact: popup.isAddedContact
isCurrentUser: popup.isCurrentUser
onContactUnblocked: {
popup.close()
popup.contactUnblocked(publicKey)
}
2022-06-22 12:16:21 +00:00
onContactBlocked: {
popup.close()
2022-06-22 12:16:21 +00:00
popup.contactBlocked(publicKey)
}
2022-06-22 12:16:21 +00:00
onContactAdded: {
popup.close()
2022-06-22 12:16:21 +00:00
popup.contactAdded(publicKey)
}
2022-06-22 12:16:21 +00:00
onContactRemoved: {
popup.close()
2020-09-16 16:00:21 +00:00
}
2022-06-22 12:16:21 +00:00
onNicknameEdited: {
popup.close()
}
}
// TODO: replace with StatusStackModal
SendContactRequestModal {
id: sendContactRequestModal
anchors.centerIn: parent
width: popup.width
height: popup.height
visible: false
header.title: qsTr("Send Contact Request to") + " " + userDisplayName
2022-06-22 12:16:21 +00:00
userPublicKey: popup.userPublicKey
userDisplayName: popup.userDisplayName
userIcon: popup.userIcon
onAccepted: popup.contactsStore.sendContactRequest(userPublicKey, message)
onClosed: popup.close()
}
rightButtons: [
StatusFlatButton {
text: userIsBlocked ?
qsTr("Unblock User") :
qsTr("Block User")
type: StatusBaseButton.Type.Danger
onClicked: userIsBlocked ? unblockUser() : blockUser()
},
StatusFlatButton {
visible: !userIsBlocked && isAddedContact
type: StatusBaseButton.Type.Danger
text: qsTr('Remove Contact')
2020-06-23 19:04:08 +00:00
onClicked: {
2022-06-22 12:16:21 +00:00
profileView.removeContactConfirmationDialog.parentPopup = popup;
profileView.removeContactConfirmationDialog.open();
}
},
StatusButton {
text: qsTr("Send Contact Request")
visible: !userIsBlocked && !isAddedContact
onClicked: sendContactRequestModal.open()
}
]
}