Skip to content

Commit

Permalink
Add strict matches to room filters predicate (#1379)
Browse files Browse the repository at this point in the history
* Add strict matches to room filters predicate

* Add changelog

Co-authored-by: Arnaud Ringenbach <arnaud.ringenbach@niji.fr>
  • Loading branch information
aringenbach and aringenbach authored Feb 25, 2022
1 parent 7fbeac5 commit bb3fe71
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
13 changes: 11 additions & 2 deletions MatrixSDK/Data/RoomList/Common/MXRoomListDataFilterable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,20 @@ extension MXRoomListDataFilterable {
MXMembership.unknown.rawValue)
predicates.append(memberPredicate)
}

if !filterOptions.dataTypes.isEmpty {
let predicate = NSPredicate(format: "(%K & %d) != 0",
let predicate: NSPredicate
if filterOptions.strictMatches {
predicate = NSPredicate(format: "(%K & %d) == %d",
#keyPath(MXRoomSummaryProtocol.dataTypes),
filterOptions.dataTypes.rawValue,
filterOptions.dataTypes.rawValue)

} else {
predicate = NSPredicate(format: "(%K & %d) != 0",
#keyPath(MXRoomSummaryProtocol.dataTypes),
filterOptions.dataTypes.rawValue)
}
predicates.append(predicate)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,18 @@ extension MXCoreDataRoomListDataFetcher: MXRoomListDataFilterable {

// data types
if !filterOptions.dataTypes.isEmpty {
let predicate = NSPredicate(format: "(%K & %d) != 0",
let predicate: NSPredicate
if filterOptions.strictMatches {
predicate = NSPredicate(format: "(%K & %d) == %d",
#keyPath(MXRoomSummaryMO.s_dataTypesInt),
filterOptions.dataTypes.rawValue,
filterOptions.dataTypes.rawValue)

} else {
predicate = NSPredicate(format: "(%K & %d) != 0",
#keyPath(MXRoomSummaryMO.s_dataTypesInt),
filterOptions.dataTypes.rawValue)
}
predicates.append(predicate)
}

Expand Down
9 changes: 8 additions & 1 deletion MatrixSDK/Data/RoomList/MXRoomListDataFilterOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public struct MXRoomListDataFilterOptions: Equatable {
/// Flag to hide any rooms where the user's membership is unknown. This has no effect when `onlySuggested` is `true`.
/// When set to `false`, rooms that have been cached during peeking may be included in the filtered results.
public let hideUnknownMembershipRooms: Bool

/// Flag to show only rooms that matches all the provided `dataTypes`. This has no effect when `onlySuggested` is `true`
public let strictMatches: Bool

/// Initializer
/// - Parameters:
Expand All @@ -52,19 +55,23 @@ public struct MXRoomListDataFilterOptions: Equatable {
/// - query: search query
/// - space: active space
/// - showAllRoomsInHomeSpace: flag to show all rooms in home space (when `space` is not provided)
/// - hideUnknownMembershipRooms: flag to hide any rooms where the user's membership is unknown
/// - strictMatches: flag to show only rooms that matches all the provided data types
public init(dataTypes: MXRoomSummaryDataTypes = MXRoomListDataFilterOptions.emptyDataTypes,
notDataTypes: MXRoomSummaryDataTypes = [.hidden, .conferenceUser, .space],
onlySuggested: Bool = false,
query: String? = nil,
space: MXSpace? = nil,
showAllRoomsInHomeSpace: Bool,
hideUnknownMembershipRooms: Bool = true) {
hideUnknownMembershipRooms: Bool = true,
strictMatches: Bool = false) {
self.dataTypes = dataTypes
self.notDataTypes = notDataTypes
self.onlySuggested = onlySuggested
self.query = query
self.space = space
self.showAllRoomsInHomeSpace = showAllRoomsInHomeSpace
self.hideUnknownMembershipRooms = hideUnknownMembershipRooms
self.strictMatches = strictMatches
}
}
1 change: 1 addition & 0 deletions changelog.d/pr-1379.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Room data filters: strict matches support

0 comments on commit bb3fe71

Please sign in to comment.