mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Check network reachability before attempting to restart the sync service
This commit is contained in:
@@ -23,6 +23,7 @@ class ClientProxy: ClientProxyProtocol {
|
||||
private let client: ClientProtocol
|
||||
private let backgroundTaskService: BackgroundTaskServiceProtocol
|
||||
private let appSettings: AppSettings
|
||||
private let networkMonitor: NetworkMonitorProtocol
|
||||
|
||||
private var sessionVerificationControllerProxy: SessionVerificationControllerProxy?
|
||||
private let mediaLoader: MediaLoaderProtocol
|
||||
@@ -77,10 +78,14 @@ class ClientProxy: ClientProxyProtocol {
|
||||
loadingStateSubject.asCurrentValuePublisher()
|
||||
}
|
||||
|
||||
init(client: ClientProtocol, backgroundTaskService: BackgroundTaskServiceProtocol, appSettings: AppSettings) async {
|
||||
init(client: ClientProtocol,
|
||||
backgroundTaskService: BackgroundTaskServiceProtocol,
|
||||
appSettings: AppSettings,
|
||||
networkMonitor: NetworkMonitorProtocol) async {
|
||||
self.client = client
|
||||
self.backgroundTaskService = backgroundTaskService
|
||||
self.appSettings = appSettings
|
||||
self.networkMonitor = networkMonitor
|
||||
|
||||
clientQueue = .init(label: "ClientProxyQueue", attributes: .concurrent)
|
||||
|
||||
@@ -94,6 +99,16 @@ class ClientProxy: ClientProxyProtocol {
|
||||
self?.callbacks.send(.receivedAuthError(isSoftLogout: isSoftLogout))
|
||||
})
|
||||
|
||||
networkMonitor.reachabilityPublisher
|
||||
.removeDuplicates()
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] reachability in
|
||||
if reachability == .reachable {
|
||||
self?.startSync()
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
await configureAppService()
|
||||
|
||||
loadUserAvatarURLFromCache()
|
||||
@@ -136,6 +151,11 @@ class ClientProxy: ClientProxyProtocol {
|
||||
return
|
||||
}
|
||||
|
||||
guard networkMonitor.reachabilityPublisher.value == .reachable else {
|
||||
MXLog.warning("Ignoring request, network unreachable.")
|
||||
return
|
||||
}
|
||||
|
||||
MXLog.info("Starting sync")
|
||||
|
||||
Task {
|
||||
|
||||
Reference in New Issue
Block a user