diff --git a/ElementX/Sources/Services/Client/ClientProxy.swift b/ElementX/Sources/Services/Client/ClientProxy.swift index e8c1aff32..904a4e0f5 100644 --- a/ElementX/Sources/Services/Client/ClientProxy.swift +++ b/ElementX/Sources/Services/Client/ClientProxy.swift @@ -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) } } }) diff --git a/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift index 519e98aac..595629395 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift @@ -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) { } } diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift index 98d36f74c..a88392b57 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift @@ -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)") diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift index 0fcab5802..2c355b4c5 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProviderProtocol.swift @@ -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) }