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

302 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 store
2020-09-17 14:26:26 +00:00
property var identicon: ""
property var userName: ""
property string nickname: ""
2020-09-17 14:26:26 +00:00
property var fromAuthor: ""
property var text: ""
property var alias: ""
readonly property int innerMargin: 20
property bool isEnsVerified: false
property bool isBlocked: 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(_showFooter, userNameParam, fromAuthorParam, identiconParam, textParam, nicknameParam) {
userName = userNameParam || ""
nickname = nicknameParam || ""
fromAuthor = fromAuthorParam || ""
identicon = identiconParam || ""
text = textParam || ""
isEnsVerified = RootStore.isEnsVerified(this.fromAuthor)
isBlocked = RootStore.isContactBlocked(this.fromAuthor);
alias = RootStore.alias(this.fromAuthor) || ""
isCurrentUser = userProfile.pubKey === this.fromAuthor
showFooter = _showFooter;
2020-06-17 21:43:26 +00:00
popup.open()
}
// Not Refactored Yet
// header.title: Utils.removeStatusEns(isCurrentUser ? profileModel.ens.preferredUsername || userName : userName)
header.subTitle: isEnsVerified ? alias : fromAuthor
header.subTitleElide: Text.ElideMiddle
header.image.source: identicon
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: ((isCurrentUser && userProfile.ensName) || isEnsVerified) ?
qsTr("ENS username") :
qsTr("Username")
subTitle: isCurrentUser ? userProfile.name : userName
tooltip.text: qsTr("Copy to clipboard")
icon.name: "copy"
iconButton.onClicked: {
globalUtils.copyToClipboard(userName)
tooltip.visible = !tooltip.visible
}
width: parent.width
}
StatusDescriptionListItem {
title: qsTr("Chat key")
subTitle: fromAuthor
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(userName)
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 (isEnsVerified) {
user = userName.startsWith("@") ? userName.substring(1) : userName
}
}
if (user === ""){
user = fromAuthor.substr(0, 4) + "..." + fromAuthor.substr(fromAuthor.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 (isEnsVerified) {
user = userName.startsWith("@") ? userName.substring(1) : userName
}
}
if (user === ""){
user = fromAuthor
}
globalUtils.copyToClipboard(Constants.userLinkPrefix + user)
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: nickname ? nickname : 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(fromAuthor)
anchors.horizontalCenter: parent.horizontalCenter
height: 212
width: 212
mipmap: true
smooth: false
}
}
UnblockContactConfirmationDialog {
id: unblockContactConfirmationDialog
onUnblockButtonClicked: {
RootStore.contactsModuleInst.unblockContact(fromAuthor)
unblockContactConfirmationDialog.close();
popup.close()
popup.contactUnblocked(fromAuthor)
}
}
BlockContactConfirmationDialog {
id: blockContactConfirmationDialog
onBlockButtonClicked: {
RootStore.contactsModuleInst.blockContact(fromAuthor)
blockContactConfirmationDialog.close();
popup.close()
popup.contactBlocked(fromAuthor)
}
}
ConfirmationDialog {
id: removeContactConfirmationDialog
header.title: qsTr("Remove contact")
confirmationText: qsTr("Are you sure you want to remove this contact?")
onConfirmButtonClicked: {
if (RootStore.contactsModuleModel.isAdded(fromAuthor)) {
RootStore.contactsModuleInst.removeContact(fromAuthor);
}
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 (isEnsVerified) {
popup.userName = newUsername;
}
popup.nickname = newNickname;
RootStore.contactsModuleInst.changeContactNickname(fromAuthor, newNickname);
popup.close()
// Not Refactored Yet
// if (!!chatsModel.communities.activeCommunity) {
// chatsModel.communities.activeCommunity.triggerMembersUpdate();
// }
}
}
}
rightButtons: [
StatusFlatButton {
text: isBlocked ?
qsTr("Unblock User") :
qsTr("Block User")
type: StatusBaseButton.Type.Danger
2020-10-02 14:37:51 +00:00
onClicked: {
if (isBlocked) {
contentItem.unblockContactConfirmationDialog.contactName = userName;
contentItem.unblockContactConfirmationDialog.contactAddress = fromAuthor;
contentItem.unblockContactConfirmationDialog.open();
return;
}
contentItem.blockContactConfirmationDialog.contactName = userName;
contentItem.blockContactConfirmationDialog.contactAddress = fromAuthor;
contentItem.blockContactConfirmationDialog.open();
2020-10-02 14:37:51 +00:00
}
},
StatusFlatButton {
property bool isAdded: RootStore.contactsModuleModel.isAdded(fromAuthor)
visible: !isBlocked && 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: RootStore.contactsModuleModel.isAdded(fromAuthor)
text: qsTr("Add to contacts")
visible: !isBlocked && !isAdded
onClicked: {
popup.store.addContact(fromAuthor);
popup.contactAdded(fromAuthor);
popup.close();
}
}
]
}