#1108 - Prevent invites from stealing away the roomList's state listener

This commit is contained in:
Stefan Ceriu
2023-06-19 10:16:12 +03:00
committed by Stefan Ceriu
parent 1b90060c9e
commit ef4346fa08
4 changed files with 21 additions and 17 deletions
@@ -401,8 +401,7 @@ class ClientProxy: ClientProxyProtocol {
Task { Task {
// Subscribe to invites later as the underlying SlidingSync list is only added when entering AllRooms // Subscribe to invites later as the underlying SlidingSync list is only added when entering AllRooms
await self.inviteSummaryProvider?.subscribeIfNecessary(entriesFunction: roomListService.invites(listener:), await self.inviteSummaryProvider?.subscribeIfNecessary(entriesFunction: roomListService.invites(listener:),
// This state function is wrong but it's not used entriesLoadingStateFunction: nil)
entriesLoadingStateFunction: roomListService.entriesLoadingState(listener:))
} }
} }
}) })
@@ -42,8 +42,8 @@ class MockRoomSummaryProvider: RoomSummaryProviderProtocol {
} }
} }
func subscribeIfNecessary(entriesFunction: (RoomListEntriesListener) async throws -> RoomListEntriesResult, func subscribeIfNecessary(entriesFunction: EntriesFunction,
entriesLoadingStateFunction: (SlidingSyncListStateObserver) async throws -> RoomListEntriesLoadingStateResult) { } entriesLoadingStateFunction: LoadingStateFunction?) async { }
func updateVisibleRange(_ range: Range<Int>) { } func updateVisibleRange(_ range: Range<Int>) { }
} }
@@ -63,8 +63,8 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
.store(in: &cancellables) .store(in: &cancellables)
} }
func subscribeIfNecessary(entriesFunction: (RoomListEntriesListener) async throws -> RoomListEntriesResult, func subscribeIfNecessary(entriesFunction: EntriesFunction,
entriesLoadingStateFunction: (SlidingSyncListStateObserver) async throws -> RoomListEntriesLoadingStateResult) async { entriesLoadingStateFunction: LoadingStateFunction?) async {
guard listUpdatesTaskHandle == nil, stateUpdatesTaskHandle == nil else { guard listUpdatesTaskHandle == nil, stateUpdatesTaskHandle == nil else {
return return
} }
@@ -82,15 +82,17 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
buildSummaryForRoomListEntry(roomListEntry) buildSummaryForRoomListEntry(roomListEntry)
} }
let stateUpdatesSubscriptionResult = try await entriesLoadingStateFunction(RoomListStateObserver { [weak self] state in if let entriesLoadingStateFunction {
guard let self else { return } let stateUpdatesSubscriptionResult = try await entriesLoadingStateFunction(RoomListStateObserver { [weak self] state in
MXLog.info("\(name): Received state update: \(state)") guard let self else { return }
stateSubject.send(RoomSummaryProviderState(slidingSyncState: state)) MXLog.info("\(name): Received state update: \(state)")
}) stateSubject.send(RoomSummaryProviderState(slidingSyncState: state))
})
stateSubject.send(RoomSummaryProviderState(slidingSyncState: stateUpdatesSubscriptionResult.entriesLoadingState))
stateSubject.send(RoomSummaryProviderState(slidingSyncState: stateUpdatesSubscriptionResult.entriesLoadingState))
stateUpdatesTaskHandle = stateUpdatesSubscriptionResult.entriesLoadingStateStream
stateUpdatesTaskHandle = stateUpdatesSubscriptionResult.entriesLoadingStateStream
}
} catch { } catch {
MXLog.error("Failed setting up room list entry listener with error: \(error)") MXLog.error("Failed setting up room list entry listener with error: \(error)")
@@ -58,6 +58,9 @@ enum RoomSummary: CustomStringConvertible {
} }
protocol RoomSummaryProviderProtocol { protocol RoomSummaryProviderProtocol {
typealias EntriesFunction = (RoomListEntriesListener) async throws -> RoomListEntriesResult
typealias LoadingStateFunction = (SlidingSyncListStateObserver) async throws -> RoomListEntriesLoadingStateResult
/// Publishes the currently available room summaries /// Publishes the currently available room summaries
var roomListPublisher: CurrentValuePublisher<[RoomSummary], Never> { get } var roomListPublisher: CurrentValuePublisher<[RoomSummary], Never> { get }
@@ -66,8 +69,8 @@ protocol RoomSummaryProviderProtocol {
/// A separate subscription method is needed instead of running this in the constructor because the invites list is added later on the Rust side. /// A separate subscription method is needed instead of running this in the constructor because the invites list is added later on the Rust side.
/// Wanted to be able to build the InvitesSummaryProvider directly instead of having to inform the HomeScreenViewModel about it later /// Wanted to be able to build the InvitesSummaryProvider directly instead of having to inform the HomeScreenViewModel about it later
func subscribeIfNecessary(entriesFunction: (RoomListEntriesListener) async throws -> RoomListEntriesResult, func subscribeIfNecessary(entriesFunction: EntriesFunction,
entriesLoadingStateFunction: (SlidingSyncListStateObserver) async throws -> RoomListEntriesLoadingStateResult) async entriesLoadingStateFunction: LoadingStateFunction?) async
func updateVisibleRange(_ range: Range<Int>) func updateVisibleRange(_ range: Range<Int>)
} }