2020-06-17 19:18:31 +00:00
|
|
|
|
import QtQuick 2.13
|
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
|
import QtQuick.Layouts 1.13
|
2020-05-28 12:56:43 +00:00
|
|
|
|
import "../../../../imports"
|
|
|
|
|
import "../../../../shared"
|
2020-11-13 15:28:27 +00:00
|
|
|
|
import "../../../../shared/status"
|
2020-05-28 12:56:43 +00:00
|
|
|
|
import "./"
|
|
|
|
|
|
2020-05-29 16:27:50 +00:00
|
|
|
|
ModalPopup {
|
2020-06-22 15:51:15 +00:00
|
|
|
|
property string validationError: ""
|
|
|
|
|
|
2020-06-25 13:26:58 +00:00
|
|
|
|
property string pubKey : "";
|
|
|
|
|
property string ensUsername : "";
|
2020-11-13 15:28:27 +00:00
|
|
|
|
|
|
|
|
|
property bool loading: false;
|
2020-06-25 13:26:58 +00:00
|
|
|
|
|
2020-06-22 15:51:15 +00:00
|
|
|
|
function validate() {
|
2020-06-25 13:26:58 +00:00
|
|
|
|
if (!Utils.isChatKey(chatKey.text) && !Utils.isValidETHNamePrefix(chatKey.text)) {
|
2020-07-07 19:03:23 +00:00
|
|
|
|
validationError = "This needs to be a valid chat key or ENS username";
|
|
|
|
|
ensUsername.text = "";
|
2020-10-14 07:41:09 +00:00
|
|
|
|
} else if (profileModel.profile.pubKey === chatKey.text) {
|
|
|
|
|
validationError = qsTr("Can't chat with yourself");
|
2020-06-22 15:51:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
validationError = ""
|
|
|
|
|
}
|
|
|
|
|
return validationError === ""
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-11 21:56:28 +00:00
|
|
|
|
property var resolveENS: Backpressure.debounce(popup, 500, function (ensName){
|
2020-07-07 19:03:23 +00:00
|
|
|
|
chatsModel.resolveENS(ensName)
|
2020-11-13 15:28:27 +00:00
|
|
|
|
loading = true
|
2020-07-11 21:56:28 +00:00
|
|
|
|
});
|
2020-07-07 19:03:23 +00:00
|
|
|
|
|
2020-06-25 13:26:58 +00:00
|
|
|
|
function onKeyReleased(){
|
2020-07-07 19:03:23 +00:00
|
|
|
|
if (!validate()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-06-22 15:51:15 +00:00
|
|
|
|
|
2020-07-07 19:03:23 +00:00
|
|
|
|
chatKey.text = chatKey.text.trim();
|
|
|
|
|
|
2020-06-25 13:26:58 +00:00
|
|
|
|
if(Utils.isChatKey(chatKey.text)){
|
|
|
|
|
pubKey = chatKey.text;
|
2020-07-07 19:03:23 +00:00
|
|
|
|
ensUsername.text = "";
|
2020-06-16 18:04:56 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2020-07-07 19:03:23 +00:00
|
|
|
|
|
|
|
|
|
Qt.callLater(resolveENS, chatKey.text)
|
2020-06-25 13:26:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doJoin() {
|
2020-11-17 14:37:00 +00:00
|
|
|
|
if (!validate() || pubKey.trim() === "" || validationError !== "") return;
|
|
|
|
|
if(Utils.isChatKey(chatKey.text)){
|
|
|
|
|
chatsModel.joinChat(pubKey, Constants.chatTypeOneToOne);
|
|
|
|
|
} else {
|
|
|
|
|
chatsModel.joinChatWithENS(pubKey, chatKey.text);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-15 16:24:21 +00:00
|
|
|
|
popup.close();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 12:56:43 +00:00
|
|
|
|
id: popup
|
2020-07-06 20:39:55 +00:00
|
|
|
|
//% "New chat"
|
|
|
|
|
title: qsTrId("new-chat")
|
2020-05-29 16:27:50 +00:00
|
|
|
|
|
2020-05-29 18:38:11 +00:00
|
|
|
|
onOpened: {
|
|
|
|
|
chatKey.text = "";
|
2020-06-25 13:26:58 +00:00
|
|
|
|
pubKey = "";
|
2020-07-07 19:03:23 +00:00
|
|
|
|
ensUsername.text = "";
|
2020-05-29 18:38:11 +00:00
|
|
|
|
chatKey.forceActiveFocus(Qt.MouseFocusReason)
|
2020-12-06 22:15:51 +00:00
|
|
|
|
noContactsRect.visible = !profileModel.contacts.list.hasAddedContacts()
|
2020-05-29 18:38:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-15 16:24:21 +00:00
|
|
|
|
Input {
|
|
|
|
|
id: chatKey
|
2020-07-06 20:39:55 +00:00
|
|
|
|
//% "Enter ENS username or chat key"
|
|
|
|
|
placeholderText: qsTrId("enter-contact-code")
|
2020-06-15 16:24:21 +00:00
|
|
|
|
Keys.onEnterPressed: doJoin()
|
|
|
|
|
Keys.onReturnPressed: doJoin()
|
2020-06-22 15:51:15 +00:00
|
|
|
|
validationError: popup.validationError
|
2020-06-25 13:26:58 +00:00
|
|
|
|
Keys.onReleased: {
|
|
|
|
|
onKeyReleased();
|
2020-06-22 15:51:15 +00:00
|
|
|
|
}
|
2020-07-07 19:03:23 +00:00
|
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
|
target: chatsModel
|
|
|
|
|
onEnsWasResolved: {
|
|
|
|
|
if(chatKey.text == ""){
|
|
|
|
|
ensUsername.text == "";
|
|
|
|
|
pubKey = "";
|
|
|
|
|
} else if(resolvedPubKey == ""){
|
2020-09-14 12:12:47 +00:00
|
|
|
|
//% "User not found"
|
|
|
|
|
ensUsername.text = qsTrId("user-not-found");
|
2020-07-07 19:03:23 +00:00
|
|
|
|
pubKey = "";
|
|
|
|
|
} else {
|
2020-11-17 14:37:00 +00:00
|
|
|
|
if (profileModel.profile.pubKey === resolvedPubKey) {
|
|
|
|
|
validationError = qsTr("Can't chat with yourself");
|
|
|
|
|
} else {
|
|
|
|
|
ensUsername.text = chatsModel.formatENSUsername(chatKey.text) + " • " + Utils.compactAddress(resolvedPubKey, 4)
|
|
|
|
|
pubKey = resolvedPubKey;
|
|
|
|
|
}
|
2020-07-07 19:03:23 +00:00
|
|
|
|
}
|
2020-11-13 15:28:27 +00:00
|
|
|
|
loading = false;
|
2020-07-07 19:03:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-29 16:27:50 +00:00
|
|
|
|
}
|
2020-06-25 13:26:58 +00:00
|
|
|
|
|
2020-07-13 18:45:54 +00:00
|
|
|
|
StyledText {
|
2020-06-25 13:26:58 +00:00
|
|
|
|
id: ensUsername
|
|
|
|
|
anchors.top: chatKey.bottom
|
2020-07-02 15:14:31 +00:00
|
|
|
|
anchors.topMargin: Style.current.padding
|
|
|
|
|
color: Style.current.darkGrey
|
2020-06-25 13:26:58 +00:00
|
|
|
|
font.pixelSize: 12
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
anchors.top: ensUsername.bottom
|
2020-07-11 21:56:28 +00:00
|
|
|
|
anchors.topMargin: 90
|
2020-06-25 13:26:58 +00:00
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
|
|
ScrollView {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
|
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
2020-06-30 21:35:24 +00:00
|
|
|
|
ScrollBar.vertical.policy: contactListView.contentHeight > contactListView.height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff
|
2020-05-28 12:56:43 +00:00
|
|
|
|
|
2020-06-25 13:26:58 +00:00
|
|
|
|
ListView {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
spacing: 0
|
|
|
|
|
clip: true
|
|
|
|
|
id: contactListView
|
2020-12-06 22:15:51 +00:00
|
|
|
|
model: profileModel.contacts.list
|
2020-06-25 13:26:58 +00:00
|
|
|
|
delegate: Contact {
|
|
|
|
|
showCheckbox: false
|
|
|
|
|
pubKey: model.pubKey
|
|
|
|
|
isContact: model.isContact
|
2020-06-30 21:35:24 +00:00
|
|
|
|
isUser: false
|
2020-06-25 13:26:58 +00:00
|
|
|
|
name: model.name
|
|
|
|
|
address: model.address
|
2020-11-30 17:03:52 +00:00
|
|
|
|
identicon: model.thumbnailImage || model.identicon
|
2020-06-25 13:26:58 +00:00
|
|
|
|
onItemChecked: function(pubKey, itemChecked){
|
|
|
|
|
chatsModel.joinChat(pubKey, Constants.chatTypeOneToOne);
|
|
|
|
|
popup.close()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-10 02:14:21 +00:00
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: noContactsRect
|
|
|
|
|
width: 260
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
StyledText {
|
|
|
|
|
id: noContacts
|
2020-08-26 15:52:26 +00:00
|
|
|
|
//% "You don’t have any contacts yet. Invite your friends to start chatting."
|
|
|
|
|
text: qsTrId("you-don-t-have-any-contacts-yet--invite-your-friends-to-start-chatting-")
|
2020-08-10 02:14:21 +00:00
|
|
|
|
color: Style.current.darkGrey
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.topMargin: Style.current.padding
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
|
}
|
|
|
|
|
StyledButton {
|
|
|
|
|
//% "Invite friends"
|
|
|
|
|
label: qsTrId("invite-friends")
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
anchors.top: noContacts.bottom
|
|
|
|
|
anchors.topMargin: Style.current.xlPadding
|
|
|
|
|
onClicked: {
|
|
|
|
|
inviteFriendsPopup.open()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
InviteFriendsPopup {
|
|
|
|
|
id: inviteFriendsPopup
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-25 13:26:58 +00:00
|
|
|
|
}
|
2020-06-16 18:04:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 20:56:10 +00:00
|
|
|
|
footer: StatusButton {
|
2020-05-29 16:27:50 +00:00
|
|
|
|
anchors.right: parent.right
|
2020-11-16 20:56:10 +00:00
|
|
|
|
id: submitBtn
|
|
|
|
|
state: loading ? "pending" : "default"
|
|
|
|
|
text: qsTr("Start chat")
|
|
|
|
|
enabled: pubKey !== ""
|
|
|
|
|
onClicked : doJoin()
|
|
|
|
|
}
|
2020-05-28 12:56:43 +00:00
|
|
|
|
}
|
2020-06-16 18:04:56 +00:00
|
|
|
|
|
|
|
|
|
/*##^##
|
|
|
|
|
Designer {
|
|
|
|
|
D{i:0;height:300;width:300}
|
|
|
|
|
}
|
|
|
|
|
##^##*/
|