mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
Adopt the new room list service syncIndicatorListener
This commit is contained in:
@@ -598,33 +598,25 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
|
|||||||
ServiceLocator.shared.analytics.signpost.beginFirstSync()
|
ServiceLocator.shared.analytics.signpost.beginFirstSync()
|
||||||
userSession.clientProxy.startSync()
|
userSession.clientProxy.startSync()
|
||||||
|
|
||||||
let identifier = "StaleDataIndicator"
|
|
||||||
|
|
||||||
func showLoadingIndicator() {
|
|
||||||
ServiceLocator.shared.userIndicatorController.submitIndicator(.init(id: identifier, type: .toast(progress: .indeterminate), title: L10n.commonSyncing, persistent: true))
|
|
||||||
}
|
|
||||||
|
|
||||||
guard clientProxyObserver == nil else {
|
guard clientProxyObserver == nil else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent the syncing indicator from showing over the offline one
|
|
||||||
if ServiceLocator.shared.networkMonitor.reachabilityPublisher.value == .reachable {
|
|
||||||
showLoadingIndicator()
|
|
||||||
}
|
|
||||||
|
|
||||||
clientProxyObserver = userSession.clientProxy
|
clientProxyObserver = userSession.clientProxy
|
||||||
.callbacks
|
.loadingStatePublisher
|
||||||
|
.removeDuplicates()
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { action in
|
.sink { state in
|
||||||
switch action {
|
let toastIdentifier = "StaleDataIndicator"
|
||||||
case .startedUpdating:
|
|
||||||
showLoadingIndicator()
|
switch state {
|
||||||
case .receivedSyncUpdate:
|
case .loading:
|
||||||
|
if ServiceLocator.shared.networkMonitor.reachabilityPublisher.value == .reachable {
|
||||||
|
ServiceLocator.shared.userIndicatorController.submitIndicator(.init(id: toastIdentifier, type: .toast(progress: .indeterminate), title: L10n.commonSyncing, persistent: true))
|
||||||
|
}
|
||||||
|
case .notLoading:
|
||||||
ServiceLocator.shared.analytics.signpost.endFirstSync()
|
ServiceLocator.shared.analytics.signpost.endFirstSync()
|
||||||
ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(identifier)
|
ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(toastIdentifier)
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class ClientProxy: ClientProxyProtocol {
|
|||||||
|
|
||||||
private var roomListService: RoomListService?
|
private var roomListService: RoomListService?
|
||||||
private var roomListStateUpdateTaskHandle: TaskHandle?
|
private var roomListStateUpdateTaskHandle: TaskHandle?
|
||||||
|
private var roomListStateLoadingStateUpdateTaskHandle: TaskHandle?
|
||||||
|
|
||||||
private var syncService: SyncService?
|
private var syncService: SyncService?
|
||||||
private var syncServiceStateUpdateTaskHandle: TaskHandle?
|
private var syncServiceStateUpdateTaskHandle: TaskHandle?
|
||||||
@@ -60,6 +61,11 @@ class ClientProxy: ClientProxyProtocol {
|
|||||||
|
|
||||||
let callbacks = PassthroughSubject<ClientProxyCallback, Never>()
|
let callbacks = PassthroughSubject<ClientProxyCallback, Never>()
|
||||||
|
|
||||||
|
private let loadingStateSubject = CurrentValueSubject<ClientProxyLoadingState, Never>(.notLoading)
|
||||||
|
var loadingStatePublisher: CurrentValuePublisher<ClientProxyLoadingState, Never> {
|
||||||
|
loadingStateSubject.asCurrentValuePublisher()
|
||||||
|
}
|
||||||
|
|
||||||
init(client: ClientProtocol, backgroundTaskService: BackgroundTaskServiceProtocol, appSettings: AppSettings) async {
|
init(client: ClientProtocol, backgroundTaskService: BackgroundTaskServiceProtocol, appSettings: AppSettings) async {
|
||||||
self.client = client
|
self.client = client
|
||||||
self.backgroundTaskService = backgroundTaskService
|
self.backgroundTaskService = backgroundTaskService
|
||||||
@@ -419,6 +425,7 @@ class ClientProxy: ClientProxyProtocol {
|
|||||||
|
|
||||||
syncServiceStateUpdateTaskHandle = createSyncServiceStateObserver(syncService)
|
syncServiceStateUpdateTaskHandle = createSyncServiceStateObserver(syncService)
|
||||||
roomListStateUpdateTaskHandle = createRoomListServiceObserver(roomListService)
|
roomListStateUpdateTaskHandle = createRoomListServiceObserver(roomListService)
|
||||||
|
roomListStateLoadingStateUpdateTaskHandle = createRoomListLoadingStateUpdateObserver(roomListService)
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
MXLog.error("Failed building room list service with error: \(error)")
|
MXLog.error("Failed building room list service with error: \(error)")
|
||||||
@@ -432,10 +439,7 @@ class ClientProxy: ClientProxyProtocol {
|
|||||||
MXLog.info("Received sync service update: \(state)")
|
MXLog.info("Received sync service update: \(state)")
|
||||||
|
|
||||||
switch state {
|
switch state {
|
||||||
case .running:
|
case .running, .terminated, .idle:
|
||||||
// Show the loading spinner when the sync service goes into running
|
|
||||||
callbacks.send(.startedUpdating)
|
|
||||||
case .terminated, .idle:
|
|
||||||
break
|
break
|
||||||
case .error:
|
case .error:
|
||||||
restartSync()
|
restartSync()
|
||||||
@@ -458,6 +462,19 @@ class ClientProxy: ClientProxyProtocol {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func createRoomListLoadingStateUpdateObserver(_ roomListService: RoomListService) -> TaskHandle {
|
||||||
|
roomListService.syncIndicator(listener: RoomListServiceSyncIndicatorListenerProxy { [weak self] state in
|
||||||
|
guard let self else { return }
|
||||||
|
|
||||||
|
switch state {
|
||||||
|
case .show:
|
||||||
|
loadingStateSubject.send(.loading)
|
||||||
|
case .hide:
|
||||||
|
loadingStateSubject.send(.notLoading)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
private func roomTupleForIdentifier(_ identifier: String) -> (RoomListItem?, Room?) {
|
private func roomTupleForIdentifier(_ identifier: String) -> (RoomListItem?, Room?) {
|
||||||
do {
|
do {
|
||||||
let roomListItem = try roomListService?.room(roomId: identifier)
|
let roomListItem = try roomListService?.room(roomId: identifier)
|
||||||
@@ -509,6 +526,18 @@ private class RoomListStateListenerProxy: RoomListServiceStateListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class RoomListServiceSyncIndicatorListenerProxy: RoomListServiceSyncIndicatorListener {
|
||||||
|
private let onUpdateClosure: (RoomListServiceSyncIndicator) -> Void
|
||||||
|
|
||||||
|
init(onUpdateClosure: @escaping (RoomListServiceSyncIndicator) -> Void) {
|
||||||
|
self.onUpdateClosure = onUpdateClosure
|
||||||
|
}
|
||||||
|
|
||||||
|
func onUpdate(syncIndicator: RoomListServiceSyncIndicator) {
|
||||||
|
onUpdateClosure(syncIndicator)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class ClientDelegateWrapper: ClientDelegate {
|
private class ClientDelegateWrapper: ClientDelegate {
|
||||||
private let authErrorCallback: (Bool) -> Void
|
private let authErrorCallback: (Bool) -> Void
|
||||||
private let tokenRefreshCallback: () -> Void
|
private let tokenRefreshCallback: () -> Void
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import Foundation
|
|||||||
import MatrixRustSDK
|
import MatrixRustSDK
|
||||||
|
|
||||||
enum ClientProxyCallback {
|
enum ClientProxyCallback {
|
||||||
case startedUpdating
|
|
||||||
case receivedSyncUpdate
|
case receivedSyncUpdate
|
||||||
case receivedAuthError(isSoftLogout: Bool)
|
case receivedAuthError(isSoftLogout: Bool)
|
||||||
case updateRestorationToken
|
case updateRestorationToken
|
||||||
@@ -33,6 +32,11 @@ enum ClientProxyCallback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ClientProxyLoadingState {
|
||||||
|
case loading
|
||||||
|
case notLoading
|
||||||
|
}
|
||||||
|
|
||||||
enum ClientProxyError: Error {
|
enum ClientProxyError: Error {
|
||||||
case failedCreatingRoom
|
case failedCreatingRoom
|
||||||
case failedRetrievingDirectRoom
|
case failedRetrievingDirectRoom
|
||||||
@@ -67,6 +71,8 @@ struct PusherConfiguration {
|
|||||||
protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
|
protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
|
||||||
var callbacks: PassthroughSubject<ClientProxyCallback, Never> { get }
|
var callbacks: PassthroughSubject<ClientProxyCallback, Never> { get }
|
||||||
|
|
||||||
|
var loadingStatePublisher: CurrentValuePublisher<ClientProxyLoadingState, Never> { get }
|
||||||
|
|
||||||
var userID: String { get }
|
var userID: String { get }
|
||||||
|
|
||||||
var deviceID: String? { get }
|
var deviceID: String? { get }
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import MatrixRustSDK
|
|||||||
class MockClientProxy: ClientProxyProtocol {
|
class MockClientProxy: ClientProxyProtocol {
|
||||||
let callbacks = PassthroughSubject<ClientProxyCallback, Never>()
|
let callbacks = PassthroughSubject<ClientProxyCallback, Never>()
|
||||||
|
|
||||||
|
let loadingStatePublisher = CurrentValuePublisher<ClientProxyLoadingState, Never>(.notLoading)
|
||||||
|
|
||||||
let userID: String
|
let userID: String
|
||||||
let deviceID: String?
|
let deviceID: String?
|
||||||
let homeserver = ""
|
let homeserver = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user