From 1d6f1185b91e157b591975bcae8031c02bdc7135 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Wed, 31 May 2023 18:16:32 +0300 Subject: [PATCH] Remove duplicates from the reachability monitor --- .../Sources/Application/AppCoordinator.swift | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index 797b6c012..8f764890f 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -436,19 +436,22 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate, private func observeNetworkState() { let reachabilityNotificationIdentifier = "io.element.elementx.reachability.notification" - networkMonitorObserver = ServiceLocator.shared.networkMonitor.reachabilityPublisher.sink { reachable in - MXLog.info("Reachability changed to \(reachable)") - - if reachable { - ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(reachabilityNotificationIdentifier) - } else { - ServiceLocator.shared.userIndicatorController.submitIndicator(.init(id: reachabilityNotificationIdentifier, - title: L10n.commonOffline, - persistent: true)) + networkMonitorObserver = ServiceLocator.shared.networkMonitor + .reachabilityPublisher + .removeDuplicates() + .sink { reachable in + MXLog.info("Reachability changed to \(reachable)") + + if reachable { + ServiceLocator.shared.userIndicatorController.retractIndicatorWithId(reachabilityNotificationIdentifier) + } else { + ServiceLocator.shared.userIndicatorController.submitIndicator(.init(id: reachabilityNotificationIdentifier, + title: L10n.commonOffline, + persistent: true)) + } } - } } - + private func handleAppRoute(_ appRoute: AppRoute) { if let userSessionFlowCoordinator { userSessionFlowCoordinator.handleAppRoute(appRoute, animated: UIApplication.shared.applicationState == .active)