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)
|
|
|
|
}
|
|
|
|
|
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
|
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)
|
|
|
|
|
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-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
|
|
|
|
|
|
|
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
|
|
|
}
|