Skip to content

Commit

Permalink
Merge branch 'when-the-revoked-view-is-shown-and-the-app-fails-to-ios…
Browse files Browse the repository at this point in the history
…-396'
  • Loading branch information
buggmagnet committed Dec 5, 2023
2 parents f61abd9 + 6578f24 commit f2594c1
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ final class TunnelStatusNotificationProvider: NotificationProvider, InAppNotific
// MARK: - Private

private func handleTunnelStatus(_ tunnelStatus: TunnelStatus) {
let invalidateForTunnelError: Bool
if case let .error(blockStateReason) = tunnelStatus.state, blockStateReason != .accountExpired {
invalidateForTunnelError = updateLastTunnelError(blockStateReason)
} else {
invalidateForTunnelError = updateLastTunnelError(nil)
}

let invalidateForTunnelError = updateLastTunnelError(tunnelStatus.state)
let invalidateForManagerError = updateTunnelManagerError(tunnelStatus.state)
let invalidateForConnectivity = updateConnectivity(tunnelStatus.state)
let invalidateForNetwork = updateNetwork(tunnelStatus.state)
Expand All @@ -72,7 +66,9 @@ final class TunnelStatusNotificationProvider: NotificationProvider, InAppNotific
}
}

private func updateLastTunnelError(_ lastTunnelError: BlockedStateReason?) -> Bool {
private func updateLastTunnelError(_ tunnelState: TunnelState) -> Bool {
let lastTunnelError = tunnelError(from: tunnelState)

if packetTunnelError != lastTunnelError {
packetTunnelError = lastTunnelError

Expand Down Expand Up @@ -121,6 +117,19 @@ final class TunnelStatusNotificationProvider: NotificationProvider, InAppNotific
return false
}

// Extracts the blocked state reason from tunnel state with a few exceptions.
// We already have dedicated screens for .accountExpired and .deviceRevoked,
// so no need to show banners as well.
private func tunnelError(from tunnelState: TunnelState) -> BlockedStateReason? {
let errorsToIgnore: [BlockedStateReason] = [.accountExpired, .deviceRevoked]

if case let .error(blockedStateReason) = tunnelState, !errorsToIgnore.contains(blockedStateReason) {
return blockedStateReason
}

return nil
}

private func notificationDescription(for packetTunnelError: BlockedStateReason) -> InAppNotificationDescriptor {
InAppNotificationDescriptor(
identifier: identifier,
Expand Down Expand Up @@ -231,7 +240,7 @@ final class TunnelStatusNotificationProvider: NotificationProvider, InAppNotific
errorString = "No servers match your settings, try changing server or other settings."
case .invalidAccount:
errorString = "You are logged in with an invalid account number. Please log out and try another one."
case .deviceRevoked, .deviceLoggedOut:
case .deviceLoggedOut:
errorString = "Unable to authenticate account. Please log out and log back in."
default:
errorString = "Unable to start tunnel connection. Please send a problem report."
Expand Down

0 comments on commit f2594c1

Please sign in to comment.