diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index df6af9010..3016dca58 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -1077,7 +1077,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg switch state { case .loading: - if self?.userSession?.clientProxy.homeserverReachabilityPublisher.value == .reachable { + if self?.userSession?.clientProxy.homeserverReachabilityPublisher.value == .reachable, + self?.appMediator.networkMonitor.reachabilityPublisher.value == .reachable { ServiceLocator.shared.userIndicatorController.submitIndicator(.init(id: toastIdentifier, type: .toast(progress: .indeterminate), title: L10n.commonSyncing, persistent: true)) } case .notLoading: diff --git a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift index a34d27044..b1195b26f 100644 --- a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift @@ -246,17 +246,17 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { MXLog.info("Homeserver reachability: \(homeserverReachability)") guard let self else { return } - switch (homeserverReachability, networkReachability) { - case (.reachable, _): + switch (networkReachability, homeserverReachability) { + case (.reachable, .reachable): flowParameters.userIndicatorController.retractIndicatorWithId(reachabilityNotificationID) - case (.unreachable, .unreachable): - flowParameters.userIndicatorController.submitIndicator(.init(id: reachabilityNotificationID, - title: L10n.commonOffline, - persistent: true)) - case (.unreachable, .reachable): + case (.reachable, .unreachable): flowParameters.userIndicatorController.submitIndicator(.init(id: reachabilityNotificationID, title: L10n.commonServerUnreachable, persistent: true)) + case (.unreachable, _): + flowParameters.userIndicatorController.submitIndicator(.init(id: reachabilityNotificationID, + title: L10n.commonOffline, + persistent: true)) } } .store(in: &cancellables) diff --git a/UnitTests/Sources/UserSessionFlowCoordinatorTests.swift b/UnitTests/Sources/UserSessionFlowCoordinatorTests.swift index 2b9d79f76..ea9c458a2 100644 --- a/UnitTests/Sources/UserSessionFlowCoordinatorTests.swift +++ b/UnitTests/Sources/UserSessionFlowCoordinatorTests.swift @@ -196,17 +196,18 @@ class UserSessionFlowCoordinatorTests: XCTestCase { homeserverReachabilitySubject.send(.reachable) try await Task.sleep(for: .milliseconds(100)) - // Then the indicator should be hidden even if the network isn't reachable. - XCTAssertEqual(userIndicatorController.submitIndicatorDelayCallsCount, 2) - XCTAssertEqual(retractReachabilityIndicatorCallsCount, 2) + // Then there should still be an offline indicator (as we don't yet support air-gapped servers on iOS). + XCTAssertEqual(userIndicatorController.submitIndicatorDelayCallsCount, 3) + XCTAssertEqual(userIndicatorController.submitIndicatorDelayReceivedArguments?.indicator.title, L10n.commonOffline) + XCTAssertEqual(retractReachabilityIndicatorCallsCount, 1) // When the network becomes reachable again. networkReachabilitySubject.send(.reachable) try await Task.sleep(for: .milliseconds(100)) - // Then nothing else should happen. - XCTAssertEqual(userIndicatorController.submitIndicatorDelayCallsCount, 2) - XCTAssertEqual(retractReachabilityIndicatorCallsCount, 3) + // Then the indicator should be hidden now as everything is back to normal + XCTAssertEqual(userIndicatorController.submitIndicatorDelayCallsCount, 3) + XCTAssertEqual(retractReachabilityIndicatorCallsCount, 2) } // MARK: - Helpers