#1108 - Prevent invites from stealing away the roomList's state listener
This commit is contained in:
committed by
Stefan Ceriu
parent
b14b78da3d
commit
48ae86fe73
@@ -401,8 +401,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
Task {
|
||||
// Subscribe to invites later as the underlying SlidingSync list is only added when entering AllRooms
|
||||
await self.inviteSummaryProvider?.subscribeIfNecessary(entriesFunction: roomListService.invites(listener:),
|
||||
// This state function is wrong but it's not used
|
||||
entriesLoadingStateFunction: roomListService.entriesLoadingState(listener:))
|
||||
entriesLoadingStateFunction: nil)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -42,8 +42,8 @@ class MockRoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func subscribeIfNecessary(entriesFunction: (RoomListEntriesListener) async throws -> RoomListEntriesResult,
|
||||
entriesLoadingStateFunction: (SlidingSyncListStateObserver) async throws -> RoomListEntriesLoadingStateResult) { }
|
||||
func subscribeIfNecessary(entriesFunction: EntriesFunction,
|
||||
entriesLoadingStateFunction: LoadingStateFunction?) async { }
|
||||
|
||||
func updateVisibleRange(_ range: Range<Int>) { }
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func subscribeIfNecessary(entriesFunction: (RoomListEntriesListener) async throws -> RoomListEntriesResult,
|
||||
entriesLoadingStateFunction: (SlidingSyncListStateObserver) async throws -> RoomListEntriesLoadingStateResult) async {
|
||||
func subscribeIfNecessary(entriesFunction: EntriesFunction,
|
||||
entriesLoadingStateFunction: LoadingStateFunction?) async {
|
||||
guard listUpdatesTaskHandle == nil, stateUpdatesTaskHandle == nil else {
|
||||
return
|
||||
}
|
||||
@@ -82,15 +82,17 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
|
||||
buildSummaryForRoomListEntry(roomListEntry)
|
||||
}
|
||||
|
||||
let stateUpdatesSubscriptionResult = try await entriesLoadingStateFunction(RoomListStateObserver { [weak self] state in
|
||||
guard let self else { return }
|
||||
MXLog.info("\(name): Received state update: \(state)")
|
||||
stateSubject.send(RoomSummaryProviderState(slidingSyncState: state))
|
||||
})
|
||||
|
||||
stateSubject.send(RoomSummaryProviderState(slidingSyncState: stateUpdatesSubscriptionResult.entriesLoadingState))
|
||||
|
||||
stateUpdatesTaskHandle = stateUpdatesSubscriptionResult.entriesLoadingStateStream
|
||||
if let entriesLoadingStateFunction {
|
||||
let stateUpdatesSubscriptionResult = try await entriesLoadingStateFunction(RoomListStateObserver { [weak self] state in
|
||||
guard let self else { return }
|
||||
MXLog.info("\(name): Received state update: \(state)")
|
||||
stateSubject.send(RoomSummaryProviderState(slidingSyncState: state))
|
||||
})
|
||||
|
||||
stateSubject.send(RoomSummaryProviderState(slidingSyncState: stateUpdatesSubscriptionResult.entriesLoadingState))
|
||||
|
||||
stateUpdatesTaskHandle = stateUpdatesSubscriptionResult.entriesLoadingStateStream
|
||||
}
|
||||
|
||||
} catch {
|
||||
MXLog.error("Failed setting up room list entry listener with error: \(error)")
|
||||
|
||||
@@ -58,6 +58,9 @@ enum RoomSummary: CustomStringConvertible {
|
||||
}
|
||||
|
||||
protocol RoomSummaryProviderProtocol {
|
||||
typealias EntriesFunction = (RoomListEntriesListener) async throws -> RoomListEntriesResult
|
||||
typealias LoadingStateFunction = (SlidingSyncListStateObserver) async throws -> RoomListEntriesLoadingStateResult
|
||||
|
||||
/// Publishes the currently available room summaries
|
||||
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.
|
||||
/// 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,
|
||||
entriesLoadingStateFunction: (SlidingSyncListStateObserver) async throws -> RoomListEntriesLoadingStateResult) async
|
||||
func subscribeIfNecessary(entriesFunction: EntriesFunction,
|
||||
entriesLoadingStateFunction: LoadingStateFunction?) async
|
||||
|
||||
func updateVisibleRange(_ range: Range<Int>)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user