Remove duplicates from the reachability monitor

This commit is contained in:
Stefan Ceriu
2023-05-31 18:16:32 +03:00
committed by Stefan Ceriu
parent e58642208d
commit 1d6f1185b9
@@ -436,17 +436,20 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate,
private func observeNetworkState() { private func observeNetworkState() {
let reachabilityNotificationIdentifier = "io.element.elementx.reachability.notification" let reachabilityNotificationIdentifier = "io.element.elementx.reachability.notification"
networkMonitorObserver = ServiceLocator.shared.networkMonitor.reachabilityPublisher.sink { reachable in networkMonitorObserver = ServiceLocator.shared.networkMonitor
MXLog.info("Reachability changed to \(reachable)") .reachabilityPublisher
.removeDuplicates()
.sink { reachable in
MXLog.info("Reachability changed to \(reachable)")
if reachable { if reachable {
ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(reachabilityNotificationIdentifier) ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(reachabilityNotificationIdentifier)
} else { } else {
ServiceLocator.shared.userIndicatorController.submitIndicator(.init(id: reachabilityNotificationIdentifier, ServiceLocator.shared.userIndicatorController.submitIndicator(.init(id: reachabilityNotificationIdentifier,
title: L10n.commonOffline, title: L10n.commonOffline,
persistent: true)) persistent: true))
}
} }
}
} }
private func handleAppRoute(_ appRoute: AppRoute) { private func handleAppRoute(_ appRoute: AppRoute) {