@@ -20,9 +20,12 @@ import Foundation
2020internal class MXSuggestedRoomListDataFetcher : NSObject , MXRoomListDataFetcher {
2121
2222 internal let fetchOptions : MXRoomListDataFetchOptions
23+ private weak var session : MXSession ?
2324 private let spaceService : MXSpaceService
2425 private let cache : MXSuggestedRoomListDataCache
2526
27+ private var allRoomSummaries : [ MXRoomSummaryProtocol ] = [ ]
28+
2629 private let multicastDelegate : MXMulticastDelegate < MXRoomListDataFetcherDelegate > = MXMulticastDelegate ( )
2730 private var space : MXSpace ? {
2831 didSet {
@@ -34,6 +37,7 @@ internal class MXSuggestedRoomListDataFetcher: NSObject, MXRoomListDataFetcher {
3437 }
3538 private var spaceEventsListener : Any ?
3639 private var currentHttpOperation : MXHTTPOperation ?
40+ private var sessionDidSyncObserver : Any ?
3741
3842 internal private( set) var data : MXRoomListData ? {
3943 didSet {
@@ -48,9 +52,11 @@ internal class MXSuggestedRoomListDataFetcher: NSObject, MXRoomListDataFetcher {
4852 }
4953
5054 internal init ( fetchOptions: MXRoomListDataFetchOptions ,
55+ session: MXSession ,
5156 spaceService: MXSpaceService ,
5257 cache: MXSuggestedRoomListDataCache = . shared) {
5358 self . fetchOptions = fetchOptions
59+ self . session = session
5460 self . spaceService = spaceService
5561 self . cache = cache
5662 self . space = fetchOptions. filterOptions. space
@@ -88,10 +94,16 @@ internal class MXSuggestedRoomListDataFetcher: NSObject, MXRoomListDataFetcher {
8894 }
8995 self . refresh ( )
9096 } )
97+ sessionDidSyncObserver = NotificationCenter . default. addObserver ( forName: . mxSessionDidSync, object: nil , queue: OperationQueue . main) { [ weak self] notification in
98+ self ? . updateData ( )
99+ }
91100 }
92101
93102 private func removeDataObservers( for space: MXSpace ? ) {
94103 space? . room? . removeListener ( spaceEventsListener)
104+ if let observer = sessionDidSyncObserver {
105+ NotificationCenter . default. removeObserver ( observer)
106+ }
95107 }
96108
97109 internal func paginate( ) {
@@ -201,12 +213,24 @@ internal class MXSuggestedRoomListDataFetcher: NSObject, MXRoomListDataFetcher {
201213
202214 private func computeData( from childInfos: [ MXSpaceChildInfo ] ) {
203215 // create room summary objects
204- var rooms : [ MXRoomSummaryProtocol ] = childInfos. map ( { MXRoomSummary ( spaceChildInfo: $0) } )
216+ var rooms : [ MXRoomSummaryProtocol ] = childInfos. compactMap ( { MXRoomSummary ( spaceChildInfo: $0) } )
205217 rooms = filterRooms ( rooms)
206218 rooms = sortRooms ( rooms)
219+ allRoomSummaries = rooms
220+ updateData ( )
221+ }
222+
223+ private func updateData( ) {
224+ let summaries = allRoomSummaries. filter { summary in
225+ guard let room = self . session? . room ( withRoomId: summary. roomId) , let localsummary = room. summary else {
226+ return true
227+ }
228+ return localsummary. membership != . join && localsummary. membership != . invite && localsummary. membership != . ban
229+ }
230+
207231 // we don't know total rooms count, passing as current number of rooms
208- self . data = MXRoomListData ( rooms: rooms ,
209- counts: MXStoreRoomListDataCounts ( withRooms: rooms ,
232+ self . data = MXRoomListData ( rooms: summaries ,
233+ counts: MXStoreRoomListDataCounts ( withRooms: summaries ,
210234 total: nil ) ,
211235 paginationOptions: fetchOptions. paginationOptions)
212236 }
0 commit comments