fix(settings/messaging): remove imperative filtering from ContactPanel

fixes: #6673
iterates: #6509
This commit is contained in:
Patryk Osmaczko 2022-08-16 13:07:02 +02:00 committed by osmaczko
parent 9ecf2af3f1
commit e9a307c383
2 changed files with 35 additions and 63 deletions

View File

@ -19,7 +19,6 @@ import shared.controls.chat.menuItems 1.0
StatusListItem { StatusListItem {
id: container id: container
width: parent.width width: parent.width
visible: container.isContact && (container.searchStr == "" || container.name.includes(container.searchStr))
height: visible ? implicitHeight : 0 height: visible ? implicitHeight : 0
title: container.name title: container.name
@ -35,8 +34,6 @@ StatusListItem {
property bool isUntrustworthy: false property bool isUntrustworthy: false
property int verificationRequestStatus: 0 property int verificationRequestStatus: 0
property string searchStr: ""
property bool showSendMessageButton: false property bool showSendMessageButton: false
property bool showRejectContactRequestButton: false property bool showRejectContactRequestButton: false
property bool showAcceptContactRequestButton: false property bool showAcceptContactRequestButton: false

View File

@ -13,6 +13,8 @@ import shared.panels 1.0
import "../../Chat/popups" import "../../Chat/popups"
import "." import "."
import SortFilterProxyModel 0.2
Item { Item {
id: contactListRoot id: contactListRoot
@ -24,7 +26,6 @@ Item {
property string title: "" property string title: ""
property string searchString: "" property string searchString: ""
readonly property string lowerCaseSearchString: searchString.toLowerCase()
readonly property int count: contactsList.count readonly property int count: contactsList.count
signal openContactContextMenu(string publicKey, string name, string icon) signal openContactContextMenu(string publicKey, string name, string icon)
@ -36,61 +37,17 @@ Item {
signal rejectionRemoved(string publicKey) signal rejectionRemoved(string publicKey)
signal textClicked(string publicKey) signal textClicked(string publicKey)
visible: contactsList.count > 0
StyledText { StyledText {
id: title id: title
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: Style.current.padding anchors.leftMargin: Style.current.padding
visible: contactListRoot.title !== "" visible: contactsList.count > 0 && contactListRoot.title !== ""
text: contactListRoot.title text: contactListRoot.title
font.weight: Font.Medium font.weight: Font.Medium
font.pixelSize: 15 font.pixelSize: 15
color: Style.current.secondaryText color: Style.current.secondaryText
} }
DelegateModel {
id: delegateModel
function update() {
var visible = [];
for (var i = 0; i < items.count; ++i) {
var item = items.get(i);
if (panelUsage === Constants.contactsPanelUsage.verifiedMutualContacts) {
if(item.model.isVerified)
visible.push(item);
}
else if(panelUsage === Constants.contactsPanelUsage.mutualContacts) {
if(!item.model.isVerified)
visible.push(item);
}
else {
visible.push(item);
}
}
for (i = 0; i < visible.length; ++i) {
item = visible[i];
item.inVisible = true;
if (item.visibleIndex !== i) {
visibleItems.move(item.visibleIndex, i, 1);
}
}
}
model: contactListRoot.contactsModel
groups: [DelegateModelGroup {
id: visibleItems
name: "visible"
includeByDefault: false
}]
filterOnGroup: "visible"
items.onChanged: update()
delegate: contactPanelComponent
}
StatusListView { StatusListView {
id: contactsList id: contactsList
anchors.top: title.bottom anchors.top: title.bottom
@ -99,13 +56,40 @@ Item {
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
interactive: false interactive: false
ScrollBar.vertical.policy: contactListRoot.scrollbarOn ? ScrollBar.AlwaysOn : ScrollBar.AsNeeded ScrollBar.vertical.policy: contactListRoot.scrollbarOn ? ScrollBar.AlwaysOn : ScrollBar.AsNeeded
model: delegateModel model: SortFilterProxyModel {
id: filteredModel
sourceModel: contactListRoot.contactsModel
function panelUsagePredicate(isVerified) {
if (panelUsage === Constants.contactsPanelUsage.verifiedMutualContacts) return isVerified
if (panelUsage === Constants.contactsPanelUsage.mutualContacts) return !isVerified
return true
} }
Component { function searchPredicate(name, pubkey) {
id: contactPanelComponent if (contactListRoot.searchString === "") return true
ContactPanel { let lowerCaseSearchString = contactListRoot.searchString.toLowerCase()
let compressedPubkey = Utils.getCompressedPk(pubkey)
return name.toLowerCase().includes(lowerCaseSearchString) ||
pubkey.toLowerCase().includes(lowerCaseSearchString) ||
compressedPubkey.toLowerCase().includes(lowerCaseSearchString)
}
filters: [
ExpressionFilter { expression: filteredModel.panelUsagePredicate(model.isVerified) },
ExpressionFilter {
expression: {
contactListRoot.searchString // ensure expression is reevaluated when searchString changes
filteredModel.searchPredicate(model.displayName, model.pubKey)
}
}
]
}
delegate: ContactPanel {
id: panelDelegate id: panelDelegate
width: ListView.view.width width: ListView.view.width
contactsStore: contactListRoot.contactsStore contactsStore: contactListRoot.contactsStore
@ -118,8 +102,6 @@ Item {
isUntrustworthy: model.isUntrustworthy isUntrustworthy: model.isUntrustworthy
verificationRequestStatus: model.incomingVerificationStatus verificationRequestStatus: model.incomingVerificationStatus
searchStr: contactListRoot.searchString
showSendMessageButton: isContact && !isBlocked showSendMessageButton: isContact && !isBlocked
onOpenContactContextMenu: function (publicKey, name, icon) { onOpenContactContextMenu: function (publicKey, name, icon) {
contactListRoot.openContactContextMenu(publicKey, name, icon) contactListRoot.openContactContextMenu(publicKey, name, icon)
@ -166,13 +148,6 @@ Item {
onRejectionRemoved: contactListRoot.rejectionRemoved(publicKey) onRejectionRemoved: contactListRoot.rejectionRemoved(publicKey)
onTextClicked: contactListRoot.textClicked(publicKey) onTextClicked: contactListRoot.textClicked(publicKey)
onShowVerificationRequest: contactListRoot.showVerificationRequest(publicKey) onShowVerificationRequest: contactListRoot.showVerificationRequest(publicKey)
readonly property string compressedPkLowerCase: Utils.getCompressedPk(publicKey).toLowerCase()
visible: searchString === "" ||
name.toLowerCase().includes(lowerCaseSearchString) ||
publicKey.toLowerCase().includes(lowerCaseSearchString) ||
compressedPkLowerCase.includes(lowerCaseSearchString)
} }
} }
} }