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: {
|
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
|
|
|
}
|
2022-09-16 19:25:10 +00:00
|
|
|
|
2022-12-01 10:24:25 +00:00
|
|
|
const contactDetails = Utils.getContactDetailsAsJson(resolvedPubKey, false)
|
2022-09-16 19:25:10 +00:00
|
|
|
|
2022-12-06 11:45:22 +00:00
|
|
|
if (contactDetails.publicKey === root.rootStore.contactsStore.myPublicKey ||
|
|
|
|
contactDetails.isBlocked) {
|
|
|
|
root.suggestionsDialog.forceHide = false
|
|
|
|
return
|
|
|
|
};
|
2022-09-16 19:25:10 +00:00
|
|
|
|
|
|
|
if (contactDetails.isContact) {
|
2022-12-06 11:45:22 +00:00
|
|
|
root.rootStore.mainModuleInst.switchTo(root.rootStore.getMySectionId(), contactDetails.publicKey)
|
2022-09-16 19:25:10 +00:00
|
|
|
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-12-06 11:45:22 +00:00
|
|
|
|
|
|
|
root.suggestionsDialog.forceHide = false
|
2022-09-16 19:25:10 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|