diff --git a/Riot/Managers/Settings/RiotSettings.swift b/Riot/Managers/Settings/RiotSettings.swift index 3a070c03d..7f4adf16c 100644 --- a/Riot/Managers/Settings/RiotSettings.swift +++ b/Riot/Managers/Settings/RiotSettings.swift @@ -28,6 +28,7 @@ final class RiotSettings: NSObject { static let allowStunServerFallback = "allowStunServerFallback" static let pinRoomsWithMissedNotificationsOnHome = "pinRoomsWithMissedNotif" static let pinRoomsWithUnreadMessagesOnHome = "pinRoomsWithUnread" + static let showAllRoomsInHomeSpace = "showAllRoomsInHomeSpace" } static let shared = RiotSettings() @@ -142,6 +143,9 @@ final class RiotSettings: NSObject { @UserDefault(key: "roomsAllowToJoinPublicRooms", defaultValue: BuildSettings.roomsAllowToJoinPublicRooms, storage: defaults) var roomsAllowToJoinPublicRooms + @UserDefault(key: UserDefaultsKeys.showAllRoomsInHomeSpace, defaultValue: false, storage: defaults) + var showAllRoomsInHomeSpace + // MARK: - Room Screen @UserDefault(key: "roomScreenAllowVoIPForDirectRoom", defaultValue: BuildSettings.roomScreenAllowVoIPForDirectRoom, storage: defaults) diff --git a/Riot/Modules/Common/Recents/Service/MatrixSDK/RecentsListService.swift b/Riot/Modules/Common/Recents/Service/MatrixSDK/RecentsListService.swift index 1f48a3135..cda8f716d 100644 --- a/Riot/Modules/Common/Recents/Service/MatrixSDK/RecentsListService.swift +++ b/Riot/Modules/Common/Recents/Service/MatrixSDK/RecentsListService.swift @@ -138,6 +138,10 @@ public class RecentsListService: NSObject, RecentsListServiceProtocol { return MXSDKOptions.sharedInstance().autoAcceptRoomInvites } + private var showAllRoomsInHomeSpace: Bool { + return RiotSettings.shared.showAllRoomsInHomeSpace + } + // swiftlint:disable weak_delegate private let multicastDelegate: MXMulticastDelegate = MXMulticastDelegate() // swiftlint:enable weak_delegate @@ -253,6 +257,7 @@ public class RecentsListService: NSObject, RecentsListServiceProtocol { public func refresh() { allFetchers.forEach({ $0.fetchOptions.sortOptions = sortOptions }) + allFetchers.forEach({ $0.fetchOptions.filterOptions.showAllRoomsInHomeSpace = showAllRoomsInHomeSpace }) } public func stop() { @@ -299,6 +304,8 @@ public class RecentsListService: NSObject, RecentsListServiceProtocol { case RiotSettings.UserDefaultsKeys.pinRoomsWithMissedNotificationsOnHome, RiotSettings.UserDefaultsKeys.pinRoomsWithUnreadMessagesOnHome: refresh() + case RiotSettings.UserDefaultsKeys.showAllRoomsInHomeSpace: + refresh() default: break } @@ -357,7 +364,8 @@ public class RecentsListService: NSObject, RecentsListServiceProtocol { let filterOptions = MXRoomListDataFilterOptions(dataTypes: dataTypes, onlySuggested: onlySuggested, query: query, - space: space) + space: space, + showAllRoomsInHomeSpace: showAllRoomsInHomeSpace) let fetchOptions = MXRoomListDataFetchOptions(filterOptions: filterOptions, sortOptions: sortOptions, diff --git a/Riot/Modules/Common/Recents/Service/Mock/MockRoomSummary.swift b/Riot/Modules/Common/Recents/Service/Mock/MockRoomSummary.swift index e8c50769a..713932423 100644 --- a/Riot/Modules/Common/Recents/Service/Mock/MockRoomSummary.swift +++ b/Riot/Modules/Common/Recents/Service/Mock/MockRoomSummary.swift @@ -80,6 +80,8 @@ public class MockRoomSummary: NSObject, MXRoomSummaryProtocol { public var spaceChildInfo: MXSpaceChildInfo? + public var parentSpaceIds: Set = [] + public init(withRoomId roomId: String) { self.roomId = roomId super.init() diff --git a/Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModel.swift b/Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModel.swift index 39e38934d..7f547061b 100644 --- a/Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModel.swift +++ b/Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModel.swift @@ -45,7 +45,7 @@ class SpaceMenuViewModel: SpaceMenuViewModelType { self.menuItems = spaceMenuItems } else { self.menuItems = [ - SpaceMenuListItemViewData(action: .showAllRoomsInHomeSpace, style: .toggle, title: VectorL10n.spaceHomeShowAllRooms, icon: nil, value: MXKAppSettings.standard().showAllRoomsInHomeSpace) + SpaceMenuListItemViewData(action: .showAllRoomsInHomeSpace, style: .toggle, title: VectorL10n.spaceHomeShowAllRooms, icon: nil, value: RiotSettings.shared.showAllRoomsInHomeSpace) ] } } @@ -70,8 +70,8 @@ class SpaceMenuViewModel: SpaceMenuViewModelType { private func processAction(with action: SpaceMenuListItemAction, at indexPath: IndexPath) { switch action { case .showAllRoomsInHomeSpace: - MXKAppSettings.standard().showAllRoomsInHomeSpace = !MXKAppSettings.standard().showAllRoomsInHomeSpace - self.menuItems[indexPath.row].value = MXKAppSettings.standard().showAllRoomsInHomeSpace + RiotSettings.shared.showAllRoomsInHomeSpace.toggle() + self.menuItems[indexPath.row].value = RiotSettings.shared.showAllRoomsInHomeSpace self.viewDelegate?.spaceMenuViewModel(self, didUpdateViewState: .deselect) case .leaveSpace: self.leaveSpace()