mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 08:15:24 +00:00
Avoid re-applying identical room list filters
The home screen's filter observation fires on every view state change, so setFilter was repeatedly pushing the same filter down into the SDK. Cache the last applied filter and skip the SDK call when it hasn't changed.
This commit is contained in:
@@ -27,6 +27,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
private var listUpdatesSubscriptionResult: RoomListEntriesWithDynamicAdaptersResult?
|
||||
private var currentFilter: RoomSummaryProviderFilter?
|
||||
private var stateUpdatesTaskHandle: TaskHandle?
|
||||
|
||||
private let roomListSubject = CurrentValueSubject<[RoomSummary], Never>([])
|
||||
@@ -117,6 +118,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
})
|
||||
|
||||
// Forces the listener above to be called with the current state
|
||||
currentFilter = nil
|
||||
setFilter(.all(filters: []))
|
||||
|
||||
let stateUpdatesSubscriptionResult = try roomList.loadingState(listener: SDKListener { [loadingStateContinuation] state in
|
||||
@@ -136,6 +138,12 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
}
|
||||
|
||||
func setFilter(_ filter: RoomSummaryProviderFilter) {
|
||||
guard filter != currentFilter else {
|
||||
return
|
||||
}
|
||||
|
||||
currentFilter = filter
|
||||
|
||||
let baseFilter: [RoomListEntriesDynamicFilterKind] = [.any(filters: [.all(filters: [.nonSpace, .nonLeft]),
|
||||
.all(filters: [.space, .invite])]),
|
||||
.deduplicateVersions]
|
||||
|
||||
Reference in New Issue
Block a user