From 47327c64cf3b67b0fbba7de189609ac2fdaea920 Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 7 Jul 2019 05:49:02 -0400 Subject: [PATCH] Working filter field for room members --- src/qml/Chat/RoomSidePane/MembersView.qml | 19 ++++++++----------- src/qml/SidePane/RoomList.qml | 16 +++++----------- src/qml/utils.js | 15 +++++++++++++++ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/qml/Chat/RoomSidePane/MembersView.qml b/src/qml/Chat/RoomSidePane/MembersView.qml index e6aaddc4..f52d4a8d 100644 --- a/src/qml/Chat/RoomSidePane/MembersView.qml +++ b/src/qml/Chat/RoomSidePane/MembersView.qml @@ -2,6 +2,7 @@ import QtQuick 2.7 import QtQuick.Layouts 1.3 import SortFilterProxyModel 0.2 import "../../Base" +import "../../utils.js" as Utils HColumnLayout { property bool collapsed: false @@ -29,6 +30,13 @@ HColumnLayout { sorters: StringSorter { roleName: "displayName" } + + filters: ExpressionFilter { + function filterIt(filter, text) { + return Utils.filterMatches(filter, text) + } + expression: filterIt(filterField.text, displayName) + } } delegate: MemberDelegate {} @@ -43,17 +51,6 @@ HColumnLayout { placeholderText: qsTr("Filter members") backgroundColor: theme.sidePane.filterRooms.background - // Without this, if the user types in the field, changes of room, then - // comes back, the field will be empty but the filter still applied. - //Component.onCompleted: - //text = Backend.clients.get(chatPage.userId).getMemberFilter( - //chatPage.category, chatPage.roomId - //) - - //onTextChanged: Backend.clients.get(chatPage.userId).setMemberFilter( - //chatPage.category, chatPage.roomId, text - //) - Layout.fillWidth: true Layout.preferredHeight: theme.bottomElementsHeight } diff --git a/src/qml/SidePane/RoomList.qml b/src/qml/SidePane/RoomList.qml index cfa23f62..9243a025 100644 --- a/src/qml/SidePane/RoomList.qml +++ b/src/qml/SidePane/RoomList.qml @@ -2,6 +2,7 @@ import QtQuick 2.7 import QtQuick.Layouts 1.3 import SortFilterProxyModel 0.2 import "../Base" +import "../utils.js" as Utils HListView { property string userId: "" @@ -24,18 +25,11 @@ HListView { } ExpressionFilter { - expression: { - var filter = paneToolBar.roomFilter.toLowerCase() - var words = filter.split(" ") - var room_name = displayName.toLowerCase() - - for (var i = 0; i < words.length; i++) { - if (words[i] && room_name.indexOf(words[i]) == -1) { - return false - } - } - return true + // Utils... won't work directly in expression? + function filterIt(filter, text) { + return Utils.filterMatches(filter, text) } + expression: filterIt(paneToolBar.roomFilter, displayName) } } } diff --git a/src/qml/utils.js b/src/qml/utils.js index b729a17b..e3dca47e 100644 --- a/src/qml/utils.js +++ b/src/qml/utils.js @@ -88,3 +88,18 @@ function translatedEventContent(ev) { } return text } + + +function filterMatches(filter, text) { + filter = filter.toLowerCase() + text = text.toLowerCase() + + var words = filter.split(" ") + + for (var i = 0; i < words.length; i++) { + if (words[i] && text.indexOf(words[i]) == -1) { + return false + } + } + return true +}