diff --git a/MatrixSDK/Data/RoomList/MXRoomListDataFilterOptions.swift b/MatrixSDK/Data/RoomList/MXRoomListDataFilterOptions.swift index 1970262fe8..56bd499e98 100644 --- a/MatrixSDK/Data/RoomList/MXRoomListDataFilterOptions.swift +++ b/MatrixSDK/Data/RoomList/MXRoomListDataFilterOptions.swift @@ -40,6 +40,10 @@ public struct MXRoomListDataFilterOptions: Equatable { /// Flag to filter only suggested rooms, if set to `true`, `dataTypes` and `notDataTypes` are not valid. public let onlySuggested: Bool + /// 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 + /// Initializer /// - Parameters: /// - dataTypes: data types to fetch. Pass `MXRoomListDataFilterOptions.emptyDataTypes` not to specify any. @@ -50,13 +54,15 @@ public struct MXRoomListDataFilterOptions: Equatable { onlySuggested: Bool = false, query: String? = nil, space: MXSpace? = nil, - showAllRoomsInHomeSpace: Bool) { + showAllRoomsInHomeSpace: Bool, + hideUnknownMembershipRooms: Bool = true) { self.dataTypes = dataTypes self.notDataTypes = notDataTypes self.onlySuggested = onlySuggested self.query = query self.space = space self.showAllRoomsInHomeSpace = showAllRoomsInHomeSpace + self.hideUnknownMembershipRooms = hideUnknownMembershipRooms } /// Just to be used for in-memory data @@ -83,6 +89,12 @@ public struct MXRoomListDataFilterOptions: Equatable { } if !onlySuggested { + if hideUnknownMembershipRooms { + let memberPredicate = NSPredicate(format: "%K != %d", + #keyPath(MXRoomSummaryProtocol.membership), MXMembership.unknown.rawValue) + subpredicates.append(memberPredicate) + } + if !dataTypes.isEmpty { let subpredicate = NSPredicate(format: "(%K & %d) != 0", #keyPath(MXRoomSummaryProtocol.dataTypes), dataTypes.rawValue) @@ -119,9 +131,9 @@ public struct MXRoomListDataFilterOptions: Equatable { #keyPath(MXRoomSummaryProtocol.dataTypes), favoritedDataTypes.rawValue) let subpredicate4_1 = NSPredicate(format: "%K == NULL", - #keyPath(MXRoomSummaryProtocol.parentSpaceIds)) + #keyPath(MXRoomSummaryProtocol.parentSpaceIds)) let subpredicate4_2 = NSPredicate(format: "%K.@count == 0", - #keyPath(MXRoomSummaryProtocol.parentSpaceIds)) + #keyPath(MXRoomSummaryProtocol.parentSpaceIds)) let subpredicate4 = NSCompoundPredicate(type: .or, subpredicates: [subpredicate4_1, subpredicate4_2]) diff --git a/MatrixSDK/MXSession.h b/MatrixSDK/MXSession.h index c973937e3f..b4b2d9142d 100644 --- a/MatrixSDK/MXSession.h +++ b/MatrixSDK/MXSession.h @@ -503,6 +503,16 @@ FOUNDATION_EXPORT NSString *const kMXSessionNoRoomTag; */ @property (nonatomic, readonly, getter=isPauseable) BOOL pauseable; +/** + Whether the user is part of a room with the membership state of `join` or + they are in the process of joining. + + @param roomIdOrAlias The ID or alias of the room to check. + + @return YES if they are. + */ +- (BOOL)isJoinedOnRoom:(NSString *)roomIdOrAlias; + #pragma mark - Class methods /** diff --git a/changelog.d/5083.bugfix b/changelog.d/5083.bugfix new file mode 100644 index 0000000000..3433752b1f --- /dev/null +++ b/changelog.d/5083.bugfix @@ -0,0 +1 @@ +MXRoomListDataFilterOptions: Filter out any cached room previews. \ No newline at end of file