mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-12 07:14:37 +00:00
50132c5a0e
* refactor(contacts): refactor 5 contact models into one and filter in QML Fixes #16549 Refactors the 5 types of contact models (all, mutuals, banned, received and sent) into only the `allContacts` and use an Adaptor on the QML side to filter into the needed models. This cleans the Nim side a lot and makes applying updates to the contacts' model way simpler. * chore(contacts): remove useless and duplicated contact properties OptionalName and isSyncing were never used. DefaultDisplayName was not really used and is actually a duplication of preferredDisplayName, so I replaced the limited usages of DefaultDisplayName by preferredDisplayName * refactor(contacts): improve updates by not removing and re-adding We used to update contact items by removing them from the models and re-adding them. This is highly inefficient. Instead, the proper way is to update only the values that changed. * user_model: onItemChanged signal removed * user_model: sorting by online status no longer needed on nim side * Chat/RootStore: contactsModel property removed * ContactsStore encapsulation improved * ContactsStore: contacts model adaptor moved outside store --------- Co-authored-by: Michał Cieślak <michalcieslak@status.im>
90 lines
2.9 KiB
QML
90 lines
2.9 KiB
QML
import QtQuick 2.15
|
|
import QtQuick.Controls 2.15
|
|
import QtQuick.Layouts 1.15
|
|
|
|
import StatusQ 0.1
|
|
import StatusQ.Core 0.1
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import AppLayouts.Chat.stores 1.0 as ChatStores
|
|
import AppLayouts.Chat.panels 1.0
|
|
|
|
import utils 1.0
|
|
import shared.controls.delegates 1.0
|
|
|
|
import SortFilterProxyModel 0.2
|
|
|
|
InlineSelectorPanel {
|
|
id: root
|
|
|
|
property ChatStores.RootStore rootStore
|
|
|
|
property alias contactsModel: suggestionsModel.sourceModel
|
|
|
|
readonly property int membersLimit: 20 // see: https://github.com/status-im/status-mobile/issues/13066
|
|
property bool limitReached: model.count >= membersLimit
|
|
|
|
property string pastedChatKey: ""
|
|
|
|
label.text: qsTr("To:")
|
|
warningLabel.text: qsTr("%1 USER LIMIT REACHED").arg(membersLimit)
|
|
warningLabel.visible: limitReached
|
|
|
|
suggestionsModel: SortFilterProxyModel {
|
|
id: suggestionsModel
|
|
|
|
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()))
|
|
}
|
|
|
|
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: [
|
|
FastExpressionFilter {
|
|
enabled: root.edit.text !== "" && root.pastedChatKey == ""
|
|
expression: {
|
|
root.edit.text // ensure expression is reevaluated when edit.text changes
|
|
return suggestionsModel.searchPredicate(model.displayName, model.localNickname, model.alias)
|
|
}
|
|
expectedRoles: ["displayName", "localNickname", "alias"]
|
|
},
|
|
FastExpressionFilter {
|
|
expression: {
|
|
root.model.count // ensure expression is reevaluated when members model changes
|
|
return suggestionsModel.notAMemberPredicate(model.pubKey)
|
|
}
|
|
expectedRoles: ["pubKey"]
|
|
},
|
|
ValueFilter {
|
|
roleName: "pubKey"
|
|
value: root.pastedChatKey
|
|
enabled: root.pastedChatKey !== ""
|
|
}
|
|
]
|
|
|
|
sorters: StringSorter {
|
|
roleName: "preferredDisplayName"
|
|
caseSensitivity: Qt.CaseInsensitive
|
|
}
|
|
}
|
|
|
|
suggestionsDelegate: ContactListItemDelegate {
|
|
highlighted: ListView.isCurrentItem
|
|
height: root.suggestionsDelegateSize.height
|
|
width: root.suggestionsDelegateSize.width
|
|
onClicked: root.entryAccepted(this)
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
root.edit.forceActiveFocus()
|
|
}
|
|
}
|