Skip to content

Commit

Permalink
Merge pull request #1283 from matrix-org/doug/5083_fix_room_previews
Browse files Browse the repository at this point in the history
Fix room previews
  • Loading branch information
pixlwave authored Nov 3, 2021
2 parents 1bc02ee + 6e45094 commit 338f78e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
18 changes: 15 additions & 3 deletions MatrixSDK/Data/RoomList/MXRoomListDataFilterOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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])

Expand Down
10 changes: 10 additions & 0 deletions MatrixSDK/MXSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
1 change: 1 addition & 0 deletions changelog.d/5083.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MXRoomListDataFilterOptions: Filter out any cached room previews.

0 comments on commit 338f78e

Please sign in to comment.