2022-09-06 13:19:50 +00:00
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
|
|
|
|
import "../../panels"
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
import shared.controls.delegates 1.0
|
|
|
|
|
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
|
|
|
InlineSelectorPanel {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property var rootStore
|
2022-09-09 07:54:13 +00:00
|
|
|
|
|
|
|
readonly property int membersLimit: 20 // see: https://github.com/status-im/status-mobile/issues/13066
|
2022-11-08 08:36:08 +00:00
|
|
|
property bool limitReached: model.count >= membersLimit
|
|
|
|
|
|
|
|
function tagText(localNickname, displayName, aliasName) {
|
|
|
|
return localNickname || displayName || aliasName
|
|
|
|
}
|
2022-09-06 13:19:50 +00:00
|
|
|
|
2023-05-15 18:22:15 +00:00
|
|
|
property string pastedChatKey: ""
|
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
label.text: qsTr("To:")
|
2022-09-09 07:54:13 +00:00
|
|
|
warningLabel.text: qsTr("%1 USER LIMIT REACHED").arg(membersLimit)
|
2022-09-06 13:19:50 +00:00
|
|
|
warningLabel.visible: limitReached
|
|
|
|
|
|
|
|
suggestionsModel: SortFilterProxyModel {
|
|
|
|
id: _suggestionsModel
|
|
|
|
|
|
|
|
sourceModel: root.rootStore.contactsModel
|
|
|
|
|
2022-11-08 08:36:08 +00:00
|
|
|
function searchPredicate(displayName, localNickname, nameAlias) {
|
|
|
|
return displayName.toLowerCase().includes(root.edit.text.toLowerCase()) ||
|
|
|
|
localNickname.toLowerCase().includes(root.edit.text.toLowerCase()) ||
|
|
|
|
(!displayName && nameAlias.toLowerCase().includes(root.edit.text.toLowerCase()))
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function notAMemberPredicate(pubKey) {
|
|
|
|
for(var i = 0; i < model.count; i++) {
|
|
|
|
var item = model.get(i)
|
|
|
|
if(item.pubKey === pubKey) return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-05-15 18:22:15 +00:00
|
|
|
function isPastedProfileLinkToContact(pubkey) {
|
|
|
|
return root.pastedChatKey === pubkey
|
|
|
|
}
|
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
filters: [
|
|
|
|
ExpressionFilter {
|
2023-05-15 18:22:15 +00:00
|
|
|
enabled: root.edit.text !== "" && root.pastedChatKey == ""
|
2022-09-06 13:19:50 +00:00
|
|
|
expression: {
|
|
|
|
root.edit.text // ensure expression is reevaluated when edit.text changes
|
2022-11-08 08:36:08 +00:00
|
|
|
return _suggestionsModel.searchPredicate(model.displayName, model.localNickname, model.alias)
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
ExpressionFilter {
|
|
|
|
expression: {
|
|
|
|
root.model.count // ensure expression is reevaluated when members model changes
|
|
|
|
return _suggestionsModel.notAMemberPredicate(model.pubKey)
|
|
|
|
}
|
2023-05-15 18:22:15 +00:00
|
|
|
},
|
|
|
|
ExpressionFilter {
|
|
|
|
enabled: root.pastedChatKey != ""
|
|
|
|
expression: {
|
|
|
|
root.pastedChatKey // ensure expression is reevaluated when members model changes
|
|
|
|
return _suggestionsModel.isPastedProfileLinkToContact(model.pubKey)
|
|
|
|
}
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
]
|
2022-11-08 08:36:08 +00:00
|
|
|
|
|
|
|
proxyRoles: ExpressionRole {
|
|
|
|
name: "title"
|
|
|
|
expression: model.localNickname || model.displayName || model.alias
|
|
|
|
}
|
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
sorters: StringSorter {
|
2022-11-08 08:36:08 +00:00
|
|
|
roleName: "title"
|
|
|
|
numericMode: true
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
suggestionsDelegate: ContactListItemDelegate {
|
|
|
|
highlighted: ListView.isCurrentItem
|
2022-11-08 08:36:08 +00:00
|
|
|
height: root.suggestionsDelegateSize.height
|
|
|
|
width: root.suggestionsDelegateSize.width
|
2022-09-06 13:19:50 +00:00
|
|
|
onClicked: root.entryAccepted(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
root.edit.forceActiveFocus()
|
|
|
|
}
|
|
|
|
}
|