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
|
|
|
|
|
|
|
|
function cleanup() {
|
2022-09-29 15:18:29 +00:00
|
|
|
root.edit.clear();
|
|
|
|
d.selectedMembers.clear();
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onEntryAccepted: {
|
2022-09-16 19:25:10 +00:00
|
|
|
if (root.limitReached)
|
|
|
|
return
|
2022-09-29 15:18:29 +00:00
|
|
|
if (d.addMember(suggestionsDelegate._pubKey, suggestionsDelegate.userName, suggestionsDelegate.isAdmin))
|
2022-09-06 13:19:50 +00:00
|
|
|
root.edit.clear()
|
|
|
|
}
|
|
|
|
|
|
|
|
onEntryRemoved: {
|
|
|
|
d.removeMember(delegate._pubKey)
|
|
|
|
}
|
|
|
|
|
2022-09-16 19:25:10 +00:00
|
|
|
onTextPasted: {
|
|
|
|
d.lookupContact(text);
|
|
|
|
}
|
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
model: SortFilterProxyModel {
|
|
|
|
sourceModel: d.selectedMembers
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate: StatusTagItem {
|
|
|
|
readonly property string _pubKey: model.pubKey
|
|
|
|
height: ListView.view.height
|
|
|
|
text: model.displayName
|
2022-09-29 15:18:29 +00:00
|
|
|
isReadonly: model.isAdmin
|
|
|
|
icon: model.isAdmin ? "crown" : ""
|
2022-09-06 13:19:50 +00:00
|
|
|
onClicked: root.entryRemoved(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
property ListModel selectedMembers: ListModel {}
|
|
|
|
|
2022-09-16 19:25:10 +00:00
|
|
|
function lookupContact(value) {
|
|
|
|
if (value.startsWith(Constants.userLinkPrefix))
|
|
|
|
value = value.slice(Constants.userLinkPrefix.length)
|
|
|
|
root.rootStore.contactsStore.resolveENS(value)
|
|
|
|
}
|
|
|
|
|
2022-09-29 15:18:29 +00:00
|
|
|
function addMember(pubKey, displayName, isAdmin) {
|
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,
|
|
|
|
"isAdmin": isAdmin
|
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
|
|
|
|
|
|
|
Connections {
|
|
|
|
enabled: root.visible
|
|
|
|
target: root.rootStore.contactsStore.mainModuleInst
|
|
|
|
onResolvedENS: {
|
|
|
|
|
|
|
|
if (resolvedPubKey === "")
|
|
|
|
return
|
|
|
|
|
|
|
|
const contactDetails = Utils.getContactDetailsAsJson(resolvedPubKey)
|
|
|
|
|
|
|
|
if (contactDetails.publicKey === root.rootStore.contactsStore.myPublicKey)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (contactDetails.isBlocked)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (contactDetails.isContact) {
|
|
|
|
if (d.addMember(contactDetails.publicKey, contactDetails.displayName))
|
|
|
|
root.cleanup()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (root.model.count === 0) {
|
2022-10-21 13:37:39 +00:00
|
|
|
Global.openContactRequestPopup(contactDetails.publicKey,
|
|
|
|
popup => popup.closed.connect(root.rejected))
|
2022-09-16 19:25:10 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|