2022-06-28 18:11:18 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
|
|
|
|
import shared.controls 1.0
|
|
|
|
import shared.views.chat 1.0
|
|
|
|
|
|
|
|
StatusModal {
|
|
|
|
id: root
|
|
|
|
|
2022-12-02 13:02:41 +00:00
|
|
|
property var contactsStore
|
|
|
|
property string publicKey
|
2022-06-28 18:11:18 +00:00
|
|
|
|
|
|
|
signal verificationRefused(string senderPublicKey)
|
|
|
|
signal responseSent(string senderPublicKey, string response)
|
|
|
|
|
2022-12-09 12:33:20 +00:00
|
|
|
function updateVerificationDetails() {
|
2022-12-02 13:02:41 +00:00
|
|
|
try {
|
|
|
|
const request = root.contactsStore.getVerificationDetailsFromAsJson(root.publicKey)
|
|
|
|
|
|
|
|
if (request.requestStatus === Constants.verificationStatus.canceled) {
|
|
|
|
root.close()
|
|
|
|
}
|
|
|
|
|
|
|
|
d.senderPublicKey = request.from,
|
|
|
|
d.senderDisplayName = request.displayName
|
|
|
|
d.senderIcon = request.icon
|
|
|
|
d.challengeText = request.challenge
|
|
|
|
d.responseText = request.response
|
|
|
|
d.messageTimestamp = request.requestedAt
|
|
|
|
d.responseTimestamp = request.repliedAt
|
|
|
|
} catch (e) {
|
|
|
|
console.error("Error getting or parsing verification data", e)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: root.contactsStore.receivedContactRequestsModel
|
2022-12-09 12:33:20 +00:00
|
|
|
|
|
|
|
function onItemChanged(pubKey) {
|
|
|
|
if (pubKey === root.publicKey)
|
|
|
|
root.updateVerificationDetails()
|
2022-12-02 13:02:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
property string senderPublicKey: ""
|
|
|
|
property string senderDisplayName: ""
|
|
|
|
property string senderIcon: ""
|
|
|
|
property string challengeText: ""
|
|
|
|
property string responseText: ""
|
|
|
|
property string messageTimestamp: ""
|
|
|
|
property string responseTimestamp: ""
|
|
|
|
}
|
|
|
|
|
|
|
|
header.title: qsTr("%1 is asking you to verify your identity").arg(d.senderDisplayName)
|
2022-06-28 18:11:18 +00:00
|
|
|
|
|
|
|
x: Math.round(((parent ? parent.width : 0) - width) / 2)
|
|
|
|
y: Math.round(((parent ? parent.height : 0) - height) / 2)
|
|
|
|
|
|
|
|
width: 480
|
|
|
|
height: 230 + verificationMessage.height + verificationResponse.height
|
|
|
|
|
|
|
|
onOpened: {
|
2022-12-09 12:33:20 +00:00
|
|
|
root.updateVerificationDetails()
|
2022-06-28 18:11:18 +00:00
|
|
|
verificationResponse.input.edit.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
|
|
|
|
|
|
|
contentItem: Item {
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
anchors.rightMargin: Style.current.padding
|
2022-12-09 12:33:20 +00:00
|
|
|
|
2022-06-28 18:11:18 +00:00
|
|
|
StatusBaseText {
|
|
|
|
id: description
|
|
|
|
width: parent.width
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: Style.current.padding
|
|
|
|
text: qsTr("%1 would like to verify your identity. Answer the question to prove your identity to %2")
|
2022-12-02 13:02:41 +00:00
|
|
|
.arg(d.senderDisplayName).arg(d.senderDisplayName)
|
2022-06-28 18:11:18 +00:00
|
|
|
font.pixelSize: 15
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageView {
|
|
|
|
id: verificationMessage
|
|
|
|
anchors.top: description.bottom
|
|
|
|
anchors.topMargin: Style.current.padding
|
2022-07-05 10:12:27 +00:00
|
|
|
width: parent.width
|
2022-06-28 18:11:18 +00:00
|
|
|
isMessage: true
|
|
|
|
shouldRepeatHeader: true
|
2022-12-02 13:02:41 +00:00
|
|
|
messageTimestamp: d.messageTimestamp
|
|
|
|
senderId: d.senderPublicKey
|
|
|
|
senderDisplayName: d.senderDisplayName
|
|
|
|
senderIsEnsVerified: d.senderPublicKey !== "" && Utils.isEnsVerified(d.senderPublicKey)
|
|
|
|
senderIcon: d.senderIcon
|
|
|
|
messageText: d.challengeText
|
2022-06-28 18:11:18 +00:00
|
|
|
messageContentType: Constants.messageContentType.messageType
|
|
|
|
placeholderMessage: true
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusInput {
|
|
|
|
id: verificationResponse
|
2022-12-02 13:02:41 +00:00
|
|
|
visible: !d.responseText
|
2022-06-28 18:11:18 +00:00
|
|
|
anchors.top: verificationMessage.bottom
|
|
|
|
anchors.topMargin: 5
|
|
|
|
input.multiline: true
|
2022-07-22 10:28:04 +00:00
|
|
|
placeholderText: qsTr("Provide answer to verification request from this contact.")
|
2022-07-26 09:49:28 +00:00
|
|
|
minimumHeight: 152
|
|
|
|
maximumHeight: 152
|
2022-06-28 18:11:18 +00:00
|
|
|
width: parent.width
|
|
|
|
input.verticalAlignment: TextEdit.AlignTop
|
|
|
|
leftPadding: 0
|
|
|
|
rightPadding: 0
|
|
|
|
charLimit: 280
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageView {
|
|
|
|
id: responseMessage
|
2022-12-02 13:02:41 +00:00
|
|
|
visible: !!d.responseText
|
2022-06-28 18:11:18 +00:00
|
|
|
anchors.top: verificationMessage.bottom
|
2022-07-05 10:12:27 +00:00
|
|
|
width: parent.width
|
2022-06-28 18:11:18 +00:00
|
|
|
isMessage: true
|
|
|
|
shouldRepeatHeader: true
|
2022-12-02 13:02:41 +00:00
|
|
|
messageTimestamp: d.responseTimestamp
|
2022-10-04 12:05:42 +00:00
|
|
|
senderId: userProfile.pubKey
|
2022-09-27 21:26:26 +00:00
|
|
|
senderDisplayName: userProfile.displayName
|
2022-12-13 09:37:27 +00:00
|
|
|
senderIsEnsVerified: !!userProfile.preferredName
|
2022-06-28 18:11:18 +00:00
|
|
|
senderIcon: userProfile.icon
|
2022-12-02 13:02:41 +00:00
|
|
|
messageText: d.responseText
|
2022-06-28 18:11:18 +00:00
|
|
|
messageContentType: Constants.messageContentType.messageType
|
|
|
|
placeholderMessage: true
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
id: responseSent
|
2022-12-02 13:02:41 +00:00
|
|
|
visible: !!d.responseText
|
2022-06-28 18:11:18 +00:00
|
|
|
width: parent.width
|
|
|
|
color: Theme.palette.baseColor1
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
anchors.top: responseMessage.bottom
|
|
|
|
anchors.topMargin: 58
|
2022-12-02 13:02:41 +00:00
|
|
|
text: qsTr("Your answer has been sent to %1.").arg(d.senderDisplayName)
|
2022-06-28 18:11:18 +00:00
|
|
|
font.pixelSize: 13
|
2022-09-27 21:26:26 +00:00
|
|
|
horizontalAlignment: Text.AlignHCenter
|
2022-06-28 18:11:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rightButtons: [
|
|
|
|
StatusButton {
|
2022-12-02 13:02:41 +00:00
|
|
|
visible: !d.responseText
|
2022-06-28 18:11:18 +00:00
|
|
|
text: qsTr("Refuse Verification")
|
|
|
|
onClicked: {
|
2022-12-02 13:02:41 +00:00
|
|
|
root.verificationRefused(d.senderPublicKey)
|
2022-06-28 18:11:18 +00:00
|
|
|
root.close();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
StatusButton {
|
|
|
|
text: qsTr("Send Answer")
|
2022-12-02 13:02:41 +00:00
|
|
|
visible: !d.responseText
|
2022-06-28 18:11:18 +00:00
|
|
|
enabled: verificationResponse.text !== ""
|
|
|
|
onClicked: {
|
2022-12-02 13:02:41 +00:00
|
|
|
root.responseSent(d.senderPublicKey, Utils.escapeHtml(verificationResponse.text))
|
|
|
|
d.responseText = verificationResponse.text
|
|
|
|
d.responseTimestamp = Date.now()
|
2022-06-28 18:11:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
StatusFlatButton {
|
2022-12-02 13:02:41 +00:00
|
|
|
visible: d.responseText
|
2022-06-28 18:11:18 +00:00
|
|
|
text: qsTr("Change answer")
|
|
|
|
onClicked: {
|
2022-12-02 13:02:41 +00:00
|
|
|
d.responseText = ""
|
2022-06-28 18:11:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
StatusButton {
|
2022-12-02 13:02:41 +00:00
|
|
|
visible: d.responseText
|
2022-06-28 18:11:18 +00:00
|
|
|
text: qsTr("Close")
|
|
|
|
onClicked: root.close()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|