2024-10-22 14:14:43 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
2022-09-06 13:19:50 +00:00
|
|
|
|
2024-10-22 14:14:43 +00:00
|
|
|
import StatusQ 0.1
|
2022-09-06 13:19:50 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
|
2024-05-22 08:13:39 +00:00
|
|
|
import AppLayouts.Chat.stores 1.0 as ChatStores
|
2024-10-22 14:14:43 +00:00
|
|
|
import AppLayouts.Chat.panels 1.0
|
2024-05-22 08:13:39 +00:00
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
import utils 1.0
|
|
|
|
import shared.controls.delegates 1.0
|
|
|
|
|
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
|
|
|
|
InlineSelectorPanel {
|
|
|
|
id: root
|
|
|
|
|
2024-05-22 08:13:39 +00:00
|
|
|
property ChatStores.RootStore 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
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
filters: [
|
2024-10-22 14:14:43 +00:00
|
|
|
FastExpressionFilter {
|
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
|
|
|
}
|
2024-10-22 14:14:43 +00:00
|
|
|
expectedRoles: ["displayName", "localNickname", "alias"]
|
2022-09-06 13:19:50 +00:00
|
|
|
},
|
2024-10-22 14:14:43 +00:00
|
|
|
FastExpressionFilter {
|
2022-09-06 13:19:50 +00:00
|
|
|
expression: {
|
|
|
|
root.model.count // ensure expression is reevaluated when members model changes
|
|
|
|
return _suggestionsModel.notAMemberPredicate(model.pubKey)
|
|
|
|
}
|
2024-10-22 14:14:43 +00:00
|
|
|
expectedRoles: ["pubKey"]
|
2023-05-15 18:22:15 +00:00
|
|
|
},
|
2024-10-22 14:14:43 +00:00
|
|
|
ValueFilter {
|
|
|
|
roleName: "pubKey"
|
|
|
|
value: root.pastedChatKey
|
|
|
|
enabled: root.pastedChatKey !== ""
|
2022-09-06 13:19:50 +00:00
|
|
|
}
|
|
|
|
]
|
2022-11-08 08:36:08 +00:00
|
|
|
|
2022-09-06 13:19:50 +00:00
|
|
|
sorters: StringSorter {
|
2024-10-22 14:14:43 +00:00
|
|
|
roleName: "preferredDisplayName"
|
|
|
|
caseSensitivity: Qt.CaseInsensitive
|
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()
|
|
|
|
}
|
|
|
|
}
|