2024-10-15 19:26:12 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
2022-03-28 14:42:26 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
2024-08-27 21:48:34 +00:00
|
|
|
import StatusQ 0.1
|
2022-03-28 14:42:26 +00:00
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Controls.Validators 0.1
|
2024-07-12 09:46:43 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Backpressure 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
2022-03-28 14:42:26 +00:00
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
|
2024-05-22 08:13:39 +00:00
|
|
|
import "../stores"
|
|
|
|
|
2022-03-28 14:42:26 +00:00
|
|
|
StatusModal {
|
|
|
|
id: root
|
|
|
|
|
2024-05-22 08:13:39 +00:00
|
|
|
property ContactsStore contactsStore
|
2022-03-28 14:42:26 +00:00
|
|
|
|
2023-05-23 12:46:16 +00:00
|
|
|
headerSettings.title: qsTr("Send Contact Request to chat key")
|
2023-08-01 12:30:44 +00:00
|
|
|
padding: d.contentMargins
|
2022-03-28 14:42:26 +00:00
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
2022-05-27 08:57:18 +00:00
|
|
|
|
2022-03-28 14:42:26 +00:00
|
|
|
readonly property int maxMsgLength: 280
|
2022-05-27 08:57:18 +00:00
|
|
|
readonly property int minMsgLength: 1
|
2022-03-28 14:42:26 +00:00
|
|
|
readonly property int msgHeight: 152
|
2022-05-27 08:57:18 +00:00
|
|
|
readonly property int contentSpacing: 5
|
|
|
|
readonly property int contentMargins: 16
|
2022-03-28 14:42:26 +00:00
|
|
|
|
|
|
|
property int minChatKeyLength: 4 // ens or chat key
|
|
|
|
property string realChatKey: ""
|
2022-10-03 10:36:38 +00:00
|
|
|
property string resolvedPubKey: ""
|
2022-03-28 14:42:26 +00:00
|
|
|
property string elidedChatKey: realChatKey.length > 32?
|
|
|
|
realChatKey.substring(0, 15) + "..." + realChatKey.substring(realChatKey.length - 16) :
|
|
|
|
realChatKey
|
|
|
|
|
|
|
|
property bool validChatKey: false
|
|
|
|
property bool showPasteButton: true
|
|
|
|
property bool showChatKeyValidationIndicator: false
|
|
|
|
property int showChatKeyValidationIndicatorSize: 24
|
|
|
|
|
|
|
|
property var lookupContact: Backpressure.debounce(root, 400, function (value) {
|
|
|
|
root.contactsStore.resolveENS(value)
|
|
|
|
})
|
2022-10-03 10:36:38 +00:00
|
|
|
|
|
|
|
function textChanged(text) {
|
2023-11-28 15:07:31 +00:00
|
|
|
const urlContactData = Utils.parseContactUrl(text)
|
|
|
|
if (urlContactData) {
|
|
|
|
// Ignore all the data from the link, because it might be malformed.
|
|
|
|
// Except for the publicKey.
|
|
|
|
d.realChatKey = urlContactData.publicKey
|
|
|
|
Qt.callLater(d.lookupContact, urlContactData.publicKey);
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-03 10:36:38 +00:00
|
|
|
d.resolvedPubKey = ""
|
|
|
|
d.realChatKey = text
|
|
|
|
|
|
|
|
if(d.realChatKey === "") {
|
|
|
|
d.showPasteButton = true
|
|
|
|
d.showChatKeyValidationIndicator = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text.length < d.minChatKeyLength) {
|
|
|
|
d.validChatKey = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-28 08:48:59 +00:00
|
|
|
if (Utils.isStatusDeepLink(text)) {
|
|
|
|
text = Utils.getChatKeyFromShareLink(text)
|
|
|
|
}
|
2022-10-03 10:36:38 +00:00
|
|
|
Qt.callLater(d.lookupContact, text);
|
|
|
|
}
|
2022-03-28 14:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: contactsStore.mainModuleInst
|
2023-01-18 09:25:36 +00:00
|
|
|
function onResolvedENS(resolvedPubKey: string, resolvedAddress: string, uuid: string) {
|
2022-03-28 14:42:26 +00:00
|
|
|
if(!d.showChatKeyValidationIndicator){
|
|
|
|
d.showPasteButton = false
|
|
|
|
d.showChatKeyValidationIndicator = true
|
|
|
|
}
|
2022-10-03 10:36:38 +00:00
|
|
|
d.resolvedPubKey = resolvedPubKey
|
|
|
|
d.validChatKey = (resolvedPubKey !== "")
|
2022-03-28 14:42:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: chatKeyValidationIndicator
|
|
|
|
Item {
|
|
|
|
implicitWidth: d.showChatKeyValidationIndicatorSize
|
|
|
|
implicitHeight: d.showChatKeyValidationIndicatorSize
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
StatusIcon {
|
|
|
|
anchors.fill: parent
|
|
|
|
icon: d.validChatKey? "checkmark-circle" : "close-circle"
|
2024-10-15 19:26:12 +00:00
|
|
|
color: d.validChatKey? Theme.palette.successColor1 : Theme.palette.dangerColor1
|
2022-03-28 14:42:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: pasteButtonComponent
|
|
|
|
StatusButton {
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2022-09-13 07:37:09 +00:00
|
|
|
borderColor: Theme.palette.primaryColor1
|
2022-03-28 14:42:26 +00:00
|
|
|
size: StatusBaseButton.Size.Tiny
|
|
|
|
text: qsTr("Paste")
|
|
|
|
onClicked: {
|
2024-08-27 21:48:34 +00:00
|
|
|
d.realChatKey = ClipboardUtils.text
|
2022-03-28 14:42:26 +00:00
|
|
|
d.showPasteButton = false
|
2022-10-03 10:36:38 +00:00
|
|
|
d.textChanged(d.realChatKey)
|
2022-03-28 14:42:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-01 12:30:44 +00:00
|
|
|
contentItem: Column {
|
|
|
|
id: content
|
|
|
|
spacing: d.contentSpacing
|
|
|
|
|
|
|
|
StatusInput {
|
|
|
|
id: chatKeyInput
|
|
|
|
input.edit.objectName: "SendContactRequestModal_ChatKey_Input"
|
|
|
|
|
|
|
|
placeholderText: qsTr("Enter chat key here")
|
|
|
|
input.text: input.edit.focus? d.realChatKey : d.elidedChatKey
|
|
|
|
input.rightComponent: {
|
|
|
|
if(d.showPasteButton)
|
|
|
|
return pasteButtonComponent
|
|
|
|
else if(d.showChatKeyValidationIndicator)
|
|
|
|
return chatKeyValidationIndicator
|
|
|
|
else
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
input.onTextChanged: {
|
|
|
|
if(input.edit.focus)
|
|
|
|
{
|
|
|
|
d.textChanged(text)
|
2022-03-28 14:42:26 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-01 12:30:44 +00:00
|
|
|
}
|
2022-03-28 14:42:26 +00:00
|
|
|
|
2023-08-01 12:30:44 +00:00
|
|
|
StatusInput {
|
|
|
|
id: messageInput
|
|
|
|
input.edit.objectName: "SendContactRequestModal_SayWhoYouAre_Input"
|
|
|
|
charLimit: d.maxMsgLength
|
|
|
|
|
|
|
|
placeholderText: qsTr("Say who you are / why you want to become a contact...")
|
|
|
|
input.multiline: true
|
|
|
|
minimumHeight: d.msgHeight
|
|
|
|
maximumHeight: d.msgHeight
|
|
|
|
input.verticalAlignment: TextEdit.AlignTop
|
|
|
|
|
|
|
|
validators: [StatusMinLengthValidator {
|
|
|
|
minLength: d.minMsgLength
|
|
|
|
errorMessage: Utils.getErrorMessage(messageInput.errors, qsTr("who are you"))
|
|
|
|
}]
|
2022-03-28 14:42:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rightButtons: [
|
|
|
|
StatusButton {
|
|
|
|
enabled: d.validChatKey && messageInput.valid
|
2022-10-26 20:00:40 +00:00
|
|
|
objectName: "SendContactRequestModal_Send_Button"
|
2022-03-28 14:42:26 +00:00
|
|
|
text: qsTr("Send Contact Request")
|
|
|
|
onClicked: {
|
2022-10-03 10:36:38 +00:00
|
|
|
root.contactsStore.sendContactRequest(d.resolvedPubKey, messageInput.text)
|
2022-03-28 14:42:26 +00:00
|
|
|
root.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|