2022-09-06 13:19:50 +00:00
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
import QtQml.Models 2.2
|
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
|
|
|
|
import "private"
|
|
|
|
|
2022-09-16 19:25:10 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
|
|
|
MembersSelectorBase {
|
|
|
|
id: root
|
|
|
|
|
2022-11-08 08:36:08 +00:00
|
|
|
limitReached: model.count >= membersLimit - 1 // -1 because creator is not on the list of members when creating chat
|
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
function cleanup() {
|
2022-11-08 08:36:08 +00:00
|
|
|
root.edit.clear()
|
|
|
|
d.selectedMembers.clear()
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
|
2022-11-08 08:36:08 +00:00
|
|
|
onEntryAccepted: if (suggestionsDelegate) {
|
2022-09-16 19:25:10 +00:00
|
|
|
if (root.limitReached)
|
|
|
|
return
|
2022-11-08 08:36:08 +00:00
|
|
|
if (d.addMember(suggestionsDelegate._pubKey, suggestionsDelegate.userName, suggestionsDelegate.nickName))
|
2022-09-06 13:19:50 +00:00
|
|
|
root.edit.clear()
|
|
|
|
}
|
|
|
|
|
2022-11-08 08:36:08 +00:00
|
|
|
onEntryRemoved: if (delegate) {
|
2022-09-06 13:19:50 +00:00
|
|
|
d.removeMember(delegate._pubKey)
|
|
|
|
}
|
|
|
|
|
2023-03-23 11:25:11 +00:00
|
|
|
edit.onTextChanged: {
|
2023-04-27 14:03:49 +00:00
|
|
|
// When edited, give a small delay in case next character is printed soon
|
|
|
|
contactLookupDelayTimer.start()
|
2023-05-15 18:22:15 +00:00
|
|
|
root.pastedChatKey = ""
|
2023-04-27 14:03:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onTextPasted: (text) => {
|
|
|
|
// When pated, process text immediately
|
|
|
|
contactLookupDelayTimer.stop() // when pasting, textChanged is still emited first
|
|
|
|
d.lookupContact(text)
|
2022-09-16 19:25:10 +00:00
|
|
|
}
|
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
model: SortFilterProxyModel {
|
|
|
|
sourceModel: d.selectedMembers
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate: StatusTagItem {
|
|
|
|
readonly property string _pubKey: model.pubKey
|
2022-11-08 08:36:08 +00:00
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
height: ListView.view.height
|
2022-11-08 08:36:08 +00:00
|
|
|
text: root.tagText(model.localNickname, model.displayName, model.alias)
|
|
|
|
|
2023-04-03 15:12:21 +00:00
|
|
|
onClosed: root.entryRemoved(this)
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
property ListModel selectedMembers: ListModel {}
|
|
|
|
|
2022-09-16 19:25:10 +00:00
|
|
|
function lookupContact(value) {
|
2023-10-26 13:58:05 +00:00
|
|
|
const urlContactData = Utils.parseContactUrl(value)
|
|
|
|
if (urlContactData) {
|
|
|
|
// Ignore all the data from the link, because it might be malformed.
|
|
|
|
// Except for the publicKey.
|
|
|
|
processContact(urlContactData.publicKey)
|
2023-07-27 11:21:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-04 15:37:44 +00:00
|
|
|
value = Utils.dropUserLinkPrefix(value.trim())
|
2023-03-23 11:25:11 +00:00
|
|
|
|
2023-04-27 14:03:49 +00:00
|
|
|
if (Utils.isChatKey(value)) {
|
2023-10-26 13:58:05 +00:00
|
|
|
processContact(value)
|
2023-04-27 14:03:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Utils.isValidEns(value)) {
|
2023-03-23 11:25:11 +00:00
|
|
|
root.rootStore.contactsStore.resolveENS(value)
|
2023-04-27 14:03:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
root.suggestionsDialog.forceHide = false
|
|
|
|
}
|
|
|
|
|
2023-10-26 13:58:05 +00:00
|
|
|
function processContact(publicKey) {
|
|
|
|
const contactDetails = Utils.getContactDetailsAsJson(publicKey, false)
|
2023-04-27 14:03:49 +00:00
|
|
|
if (contactDetails.publicKey === "") {
|
|
|
|
// not a valid key given
|
|
|
|
root.suggestionsDialog.forceHide = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contactDetails.isContact) {
|
2023-05-30 19:01:55 +00:00
|
|
|
// Is a contact, we add their name to the list
|
2023-05-15 18:22:15 +00:00
|
|
|
root.pastedChatKey = contactDetails.publicKey
|
|
|
|
root.suggestionsDialog.forceHide = false
|
2023-04-27 14:03:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-26 13:58:05 +00:00
|
|
|
const hasPendingContactRequest = root.rootStore.contactsStore.hasPendingContactRequest(contactDetails.publicKey)
|
2023-05-30 19:01:55 +00:00
|
|
|
|
|
|
|
if ((root.model.count === 0 && hasPendingContactRequest) ||
|
|
|
|
contactDetails.publicKey === root.rootStore.contactsStore.myPublicKey || contactDetails.isBlocked) {
|
|
|
|
// List is empty and we have a contact request
|
|
|
|
// OR it's our own chat key or a banned user
|
|
|
|
// Then open the contact's profile popup
|
2023-10-26 13:58:05 +00:00
|
|
|
Global.openProfilePopup(contactDetails.publicKey, null,
|
|
|
|
popup => popup.closed.connect(root.rejected))
|
2023-05-30 19:01:55 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (root.model.count === 0 && !hasPendingContactRequest) {
|
|
|
|
// List is empty and not a contact yet. Open the contact request popup
|
2024-02-16 11:56:29 +00:00
|
|
|
Global.openContactRequestPopup(contactDetails.publicKey, contactDetails,
|
2023-10-26 13:58:05 +00:00
|
|
|
popup => popup.closed.connect(root.rejected))
|
2023-04-27 14:03:49 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
root.suggestionsDialog.forceHide = false
|
2022-09-16 19:25:10 +00:00
|
|
|
}
|
|
|
|
|
2022-11-08 08:36:08 +00:00
|
|
|
function addMember(pubKey, displayName, localNickname) {
|
2022-09-16 19:25:10 +00:00
|
|
|
for (let i = 0; i < d.selectedMembers.count; ++i) {
|
|
|
|
if (d.selectedMembers.get(i).pubKey === pubKey)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
d.selectedMembers.append({
|
|
|
|
"pubKey": pubKey,
|
2022-09-29 15:18:29 +00:00
|
|
|
"displayName": displayName,
|
2022-11-08 08:36:08 +00:00
|
|
|
"localNickname": localNickname
|
2022-09-06 13:19:50 +00:00
|
|
|
})
|
2022-09-16 19:25:10 +00:00
|
|
|
return true
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
2022-09-16 19:25:10 +00:00
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
function removeMember(pubKey) {
|
|
|
|
for(var i = 0; i < d.selectedMembers.count; i++) {
|
|
|
|
const obj = d.selectedMembers.get(i)
|
|
|
|
if(obj.pubKey === pubKey) {
|
|
|
|
d.selectedMembers.remove(i)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-16 19:25:10 +00:00
|
|
|
|
2023-04-27 14:03:49 +00:00
|
|
|
Timer {
|
|
|
|
id: contactLookupDelayTimer
|
|
|
|
repeat: false
|
|
|
|
interval: 500
|
|
|
|
onTriggered: {
|
|
|
|
d.lookupContact(edit.text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-16 19:25:10 +00:00
|
|
|
Connections {
|
|
|
|
enabled: root.visible
|
|
|
|
target: root.rootStore.contactsStore.mainModuleInst
|
2023-01-18 09:25:36 +00:00
|
|
|
function onResolvedENS(resolvedPubKey: string, resolvedAddress: string, uuid: string) {
|
2022-12-06 11:45:22 +00:00
|
|
|
if (resolvedPubKey === "") {
|
|
|
|
root.suggestionsDialog.forceHide = false
|
2022-09-16 19:25:10 +00:00
|
|
|
return
|
2022-12-06 11:45:22 +00:00
|
|
|
}
|
2023-10-26 13:58:05 +00:00
|
|
|
d.processContact(resolvedPubKey)
|
2022-09-16 19:25:10 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|