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

304 lines
10 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
import StatusQ.Core.Theme 0.1
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import StatusQ.Popups 0.1
StatusModal {
id: popup
anchors.centerIn: parent
2020-10-02 13:02:56 +00:00
property Popup parentPopup
property var contactsStore
property string userPublicKey: ""
property string userDisplayName: ""
property string userName: ""
property string userNickname: ""
property string userEnsName: ""
property string userIcon: ""
property string text: ""
readonly property int innerMargin: 20
property bool userIsEnsVerified: false
property bool userIsBlocked: false
property bool isCurrentUser: false
2020-06-17 21:43:26 +00:00
signal blockButtonClicked(name: string, address: string)
signal unblockButtonClicked(name: string, address: string)
signal removeButtonClicked(address: string)
signal contactUnblocked(publicKey: string)
2020-10-02 14:37:51 +00:00
signal contactBlocked(publicKey: string)
signal contactAdded(publicKey: string)
function openPopup(publicKey) {
// All this should be improved more, but for now we leave it like this.
let 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
text = "" // this is most likely unneeded
isCurrentUser = userProfile.pubKey === publicKey
showFooter = !isCurrentUser
2020-06-17 21:43:26 +00:00
popup.open()
}
header.title: userDisplayName
header.subTitle: userIsEnsVerified ? userName : userPublicKey
header.subTitleElide: Text.ElideMiddle
header.image.source: userIcon
headerActionButton: StatusFlatRoundButton {
type: StatusFlatRoundButton.Type.Secondary
width: 32
height: 32
icon.width: 20
icon.height: 20
icon.name: "qr"
onClicked: contentItem.qrCodePopup.open()
}
contentItem: Item {
width: popup.width
height: modalContent.height
2020-06-23 19:04:08 +00:00
property alias qrCodePopup: qrCodePopup
property alias unblockContactConfirmationDialog: unblockContactConfirmationDialog
property alias blockContactConfirmationDialog: blockContactConfirmationDialog
property alias removeContactConfirmationDialog: removeContactConfirmationDialog
Column {
id: modalContent
2020-06-23 19:04:08 +00:00
anchors.top: parent.top
width: parent.width
Item {
height: 16
width: parent.width
}
StatusDescriptionListItem {
title: userIsEnsVerified ?
qsTr("ENS username") :
qsTr("Username")
subTitle: userIsEnsVerified ? userEnsName : userName
tooltip.text: qsTr("Copy to clipboard")
icon.name: "copy"
iconButton.onClicked: {
globalUtils.copyToClipboard(subTitle)
tooltip.visible = !tooltip.visible
}
width: parent.width
}
StatusDescriptionListItem {
title: qsTr("Chat key")
subTitle: userPublicKey
subTitleComponent.elide: Text.ElideMiddle
subTitleComponent.width: 320
subTitleComponent.font.family: Theme.palette.monoFont.name
tooltip.text: qsTr("Copy to clipboard")
icon.name: "copy"
iconButton.onClicked: {
globalUtils.copyToClipboard(subTitle)
tooltip.visible = !tooltip.visible
}
width: parent.width
}
StatusModalDivider {
topPadding: 12
bottomPadding: 16
}
StatusDescriptionListItem {
title: qsTr("Share Profile URL")
subTitle: {
let user = ""
if (isCurrentUser) {
user = userProfile.name
} else {
if (userIsEnsVerified) {
user = userEnsName
}
}
if (user === ""){
user = userPublicKey.substr(0, 4) + "..." + userPublicKey.substr(userPublicKey.length - 5)
}
return Constants.userLinkPrefix + user;
}
tooltip.text: qsTr("Copy to clipboard")
icon.name: "copy"
iconButton.onClicked: {
let user = ""
if (isCurrentUser) {
user = userProfile.name
} else {
if (userIsEnsVerified) {
user = userName.startsWith("@") ? userName.substring(1) : userName
}
}
if (user === ""){
user = userPublicKey
}
globalUtils.copyToClipboard(subTitle)
tooltip.visible = !tooltip.visible
}
width: parent.width
}
StatusModalDivider {
visible: !isCurrentUser
topPadding: 8
bottomPadding: 12
}
StatusDescriptionListItem {
visible: !isCurrentUser
title: qsTr("Chat settings")
subTitle: qsTr("Nickname")
value: userNickname ? userNickname : qsTr("None")
sensor.enabled: true
sensor.onClicked: {
nicknamePopup.open()
}
width: parent.width
}
Item {
visible: !isCurrentUser
width: parent.width
height: 16
}
}
// TODO: replace with StatusModal
2020-12-04 16:01:38 +00:00
ModalPopup {
id: qrCodePopup
2020-12-04 16:01:38 +00:00
width: 320
height: 320
Image {
asynchronous: true
fillMode: Image.PreserveAspectFit
source: globalUtils.qrCode(userPublicKey)
anchors.horizontalCenter: parent.horizontalCenter
height: 212
width: 212
mipmap: true
smooth: false
}
}
UnblockContactConfirmationDialog {
id: unblockContactConfirmationDialog
onUnblockButtonClicked: {
popup.contactsStore.unblockContact(userPublicKey)
unblockContactConfirmationDialog.close();
popup.close()
popup.contactUnblocked(userPublicKey)
}
}
BlockContactConfirmationDialog {
id: blockContactConfirmationDialog
onBlockButtonClicked: {
popup.contactsStore.blockContact(userPublicKey)
blockContactConfirmationDialog.close();
popup.close()
popup.contactBlocked(userPublicKey)
}
}
ConfirmationDialog {
id: removeContactConfirmationDialog
header.title: qsTr("Remove contact")
confirmationText: qsTr("Are you sure you want to remove this contact?")
onConfirmButtonClicked: {
if (popup.contactsStore.isContactAdded(userPublicKey)) {
popup.contactsStore.removeContact(userPublicKey);
}
removeContactConfirmationDialog.close();
popup.close();
2020-09-16 16:00:21 +00:00
}
}
NicknamePopup {
id: nicknamePopup
onDoneClicked: {
// Change username title only if it was not an ENS name
if (userIsEnsVerified) {
popup.userName = newUsername;
}
popup.userNickname = newNickname;
popup.contactsStore.changeContactNickname(userPublicKey, newNickname);
popup.close()
}
}
}
rightButtons: [
StatusFlatButton {
text: userIsBlocked ?
qsTr("Unblock User") :
qsTr("Block User")
type: StatusBaseButton.Type.Danger
2020-10-02 14:37:51 +00:00
onClicked: {
if (userIsBlocked) {
contentItem.unblockContactConfirmationDialog.contactName = userName;
contentItem.unblockContactConfirmationDialog.contactAddress = userPublicKey;
contentItem.unblockContactConfirmationDialog.open();
return;
}
contentItem.blockContactConfirmationDialog.contactName = userName;
contentItem.blockContactConfirmationDialog.contactAddress = userPublicKey;
contentItem.blockContactConfirmationDialog.open();
2020-10-02 14:37:51 +00:00
}
},
StatusFlatButton {
property bool isAdded: popup.contactsStore.isContactAdded(userPublicKey)
visible: !userIsBlocked && isAdded
type: StatusBaseButton.Type.Danger
text: qsTr('Remove Contact')
2020-06-23 19:04:08 +00:00
onClicked: {
contentItem.removeContactConfirmationDialog.parentPopup = popup;
contentItem.removeContactConfirmationDialog.open();
}
},
StatusButton {
property bool isAdded: popup.contactsStore.isContactAdded(userPublicKey)
text: qsTr("Add to contacts")
visible: !userIsBlocked && !isAdded
onClicked: {
popup.contactsStore.addContact(userPublicKey);
popup.contactAdded(userPublicKey);
popup.close();
}
}
]
}