feat(@desktop/contacts): support sending contact request to chat key
Fixes #5175
This commit is contained in:
parent
b4606d0363
commit
e83e5670a4
|
@ -102,6 +102,9 @@ QtObject:
|
|||
proc copyToClipboard*(self: Utils, content: string) {.slot.} =
|
||||
setClipBoardText(content)
|
||||
|
||||
proc getFromClipboard*(self: Utils): string {.slot.} =
|
||||
return getClipBoardText()
|
||||
|
||||
proc copyImageToClipboard*(self: Utils, content: string) {.slot.} =
|
||||
setClipBoardImage(content)
|
||||
|
||||
|
|
|
@ -261,19 +261,22 @@ QtObject:
|
|||
self.contacts[contact.id] = contact
|
||||
|
||||
proc addContact*(self: Service, publicKey: string) =
|
||||
var contact = self.getContactById(publicKey)
|
||||
if not contact.added:
|
||||
contact.added = true
|
||||
else:
|
||||
contact.blocked = false
|
||||
try:
|
||||
var contact = self.getContactById(publicKey)
|
||||
if not contact.added:
|
||||
contact.added = true
|
||||
else:
|
||||
contact.blocked = false
|
||||
|
||||
let response = status_contacts.addContact(contact.id, contact.name)
|
||||
if(not response.error.isNil):
|
||||
let msg = response.error.message
|
||||
error "error adding contact ", msg
|
||||
return
|
||||
self.saveContact(contact)
|
||||
self.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id))
|
||||
let response = status_contacts.addContact(contact.id, contact.name)
|
||||
if(not response.error.isNil):
|
||||
let msg = response.error.message
|
||||
error "error adding contact ", msg
|
||||
return
|
||||
self.saveContact(contact)
|
||||
self.events.emit(SIGNAL_CONTACT_ADDED, ContactArgs(contactId: contact.id))
|
||||
except Exception as e:
|
||||
error "an error occurred while edding contact ", msg=e.msg
|
||||
|
||||
proc rejectContactRequest*(self: Service, publicKey: string) =
|
||||
var contact = self.getContactById(publicKey)
|
||||
|
|
|
@ -55,8 +55,11 @@ proc publicKeyOf*(chainId: int, username: string): string =
|
|||
return ""
|
||||
|
||||
proc addressOf*(chainId: int, username: string): string =
|
||||
let res = status_ens.addressOf(chainId, username.addDomain())
|
||||
return res.result.getStr
|
||||
try:
|
||||
let res = status_ens.addressOf(chainId, username.addDomain())
|
||||
return res.result.getStr
|
||||
except:
|
||||
return ""
|
||||
|
||||
proc ownerOf*(chainId: int, username: string): string =
|
||||
let res = status_ens.ownerOf(chainId, username)
|
||||
|
|
|
@ -0,0 +1,148 @@
|
|||
import QtQuick 2.14
|
||||
import QtQuick.Controls 2.14
|
||||
import QtQuick.Layouts 1.14
|
||||
|
||||
import utils 1.0
|
||||
|
||||
import StatusQ.Core 0.1
|
||||
import StatusQ.Core.Theme 0.1
|
||||
import StatusQ.Controls 0.1
|
||||
import StatusQ.Controls.Validators 0.1
|
||||
import StatusQ.Popups 0.1
|
||||
|
||||
StatusModal {
|
||||
id: root
|
||||
|
||||
property var contactsStore
|
||||
|
||||
header.title: qsTr("Send Contact Request to chat key")
|
||||
|
||||
QtObject {
|
||||
id: d
|
||||
readonly property int maxMsgLength: 280
|
||||
readonly property int minMsgLength: 0 //TODO: update this to 1 later, when we introduce "say who you are" feature
|
||||
readonly property int msgHeight: 152
|
||||
readonly property int contentSpacing: 0
|
||||
|
||||
property int minChatKeyLength: 4 // ens or chat key
|
||||
property string realChatKey: ""
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: contactsStore.mainModuleInst
|
||||
onResolvedENS: {
|
||||
if(!d.showChatKeyValidationIndicator){
|
||||
d.showPasteButton = false
|
||||
d.showChatKeyValidationIndicator = true
|
||||
}
|
||||
d.validChatKey = resolvedPubKey !== ""
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
color: d.validChatKey? Style.current.success : Style.current.danger
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: pasteButtonComponent
|
||||
StatusButton {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
border.width: 1
|
||||
border.color: Theme.palette.primaryColor1
|
||||
size: StatusBaseButton.Size.Tiny
|
||||
text: qsTr("Paste")
|
||||
onClicked: {
|
||||
d.realChatKey = root.contactsStore.getFromClipboard()
|
||||
d.showPasteButton = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
contentItem: Column {
|
||||
id: content
|
||||
width: root.width
|
||||
spacing: d.contentSpacing
|
||||
|
||||
StatusInput {
|
||||
id: chatKeyInput
|
||||
|
||||
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.realChatKey = text
|
||||
|
||||
if(d.realChatKey === "") {
|
||||
d.showPasteButton = true
|
||||
d.showChatKeyValidationIndicator = false
|
||||
}
|
||||
|
||||
if (text.length < d.minChatKeyLength) {
|
||||
d.validChatKey = false
|
||||
return
|
||||
}
|
||||
|
||||
Qt.callLater(d.lookupContact, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StatusInput {
|
||||
id: messageInput
|
||||
charLimit: d.maxMsgLength
|
||||
|
||||
input.placeholderText: qsTr("Say who you are / why you want to become a contact...")
|
||||
input.multiline: true
|
||||
input.implicitHeight: d.msgHeight
|
||||
|
||||
validators: [StatusMinLengthValidator {
|
||||
minLength: d.minMsgLength
|
||||
errorMessage: Utils.getErrorMessage(messageInput.errors, qsTr("who are you"))
|
||||
}]
|
||||
validationMode: StatusInput.ValidationMode.Always
|
||||
}
|
||||
}
|
||||
|
||||
rightButtons: [
|
||||
StatusButton {
|
||||
id: btnCreateEdit
|
||||
enabled: d.validChatKey && messageInput.valid
|
||||
text: qsTr("Send Contact Request")
|
||||
onClicked: {
|
||||
root.contactsStore.addContact(d.realChatKey)
|
||||
root.close()
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -26,6 +26,10 @@ QtObject {
|
|||
return root.globalUtilsInst.generateAlias(pubKey)
|
||||
}
|
||||
|
||||
function getFromClipboard() {
|
||||
return root.globalUtilsInst.getFromClipboard()
|
||||
}
|
||||
|
||||
function joinPrivateChat(pubKey) {
|
||||
Global.changeAppSectionBySectionType(Constants.appSection.chat)
|
||||
let chatCommunitySectionModule = root.mainModuleInst.getChatSectionModule()
|
||||
|
|
|
@ -52,19 +52,32 @@ Item {
|
|||
Constants.settingsSubsection.messaging)
|
||||
}
|
||||
|
||||
StatusBaseText {
|
||||
id: titleText
|
||||
text: qsTr("Contacts")
|
||||
font.weight: Font.Bold
|
||||
font.pixelSize: 28
|
||||
color: Theme.palette.directColor1
|
||||
RowLayout {
|
||||
id: contactsHeader
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 56
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
|
||||
StatusBaseText {
|
||||
Layout.fillWidth: true
|
||||
text: qsTr("Contacts")
|
||||
font.weight: Font.Bold
|
||||
font.pixelSize: 28
|
||||
color: Theme.palette.directColor1
|
||||
}
|
||||
|
||||
StatusButton {
|
||||
text: qsTr("Send contact request to chat key")
|
||||
onClicked: {
|
||||
sendContactRequest.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SearchBox {
|
||||
id: searchBox
|
||||
anchors.top: titleText.bottom
|
||||
anchors.top: contactsHeader.bottom
|
||||
anchors.topMargin: 32
|
||||
width: parent.width
|
||||
input.implicitHeight: 44
|
||||
|
@ -237,5 +250,27 @@ Item {
|
|||
removeContactConfirmationDialog.close()
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: sendContactRequest
|
||||
active: false
|
||||
|
||||
function open() {
|
||||
active = true
|
||||
sendContactRequest.item.open()
|
||||
}
|
||||
function close() {
|
||||
active = false
|
||||
}
|
||||
|
||||
sourceComponent: SendContactRequestModal {
|
||||
anchors.centerIn: parent
|
||||
contactsStore: root.contactsStore
|
||||
|
||||
onClosed: {
|
||||
sendContactRequest.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 7c9d386121d18a2deb8943286a6980a62d1f7b91
|
||||
Subproject commit 8b9fe826257d316ae06047146bf4d70ae67729e1
|
|
@ -1 +1 @@
|
|||
Subproject commit d1b79f8a4c0d35e5b7accd4620c727dabfa0b223
|
||||
Subproject commit 7baaeee7b9d5c2815e071b5fc8946b17b936e0f0
|
Loading…
Reference in New Issue