Skip to content

Commit

Permalink
Merge pull request #2170 from HedvigInsurance/fix/stuck-in-login-scre…
Browse files Browse the repository at this point in the history
…ens-when-logged-out

fix/stuck-in-login-screens-when-logged-out
  • Loading branch information
StylianosGakis authored Aug 5, 2024
2 parents 8ad15f7 + d480e51 commit 59a3eff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.core.graphics.drawable.IconCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hasRoute
import com.benasher44.uuid.Uuid
import com.google.firebase.messaging.RemoteMessage
import com.hedvig.android.app.notification.getMutablePendingIntentFlags
Expand All @@ -28,6 +27,7 @@ import com.hedvig.android.featureflags.FeatureManager
import com.hedvig.android.featureflags.flags.Feature
import com.hedvig.android.logger.LogPriority.ERROR
import com.hedvig.android.logger.logcat
import com.hedvig.android.navigation.compose.typedHasRoute
import com.hedvig.android.navigation.core.AppDestination
import com.hedvig.android.navigation.core.HedvigDeepLinkContainer
import com.hedvig.android.notification.core.NotificationSender
Expand Down Expand Up @@ -76,7 +76,7 @@ class ChatNotificationSender(
val currentDestination = CurrentDestinationInMemoryStorage.currentDestination
val currentlyOnDestinationWhichForbidsShowingChatNotification =
listOfDestinationsWhichShouldNotShowChatNotification.any { clazz ->
currentDestination?.hasRoute(clazz) == true
currentDestination?.typedHasRoute(clazz) == true
}
if (currentlyOnDestinationWhichForbidsShowingChatNotification && isAppForegrounded) {
logcat { "ChatNotificationSender ignoring notification since we are showing destination $currentDestination" }
Expand Down
12 changes: 5 additions & 7 deletions app/app/src/main/kotlin/com/hedvig/android/app/ui/HedvigApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavHostController
import coil.ImageLoader
Expand All @@ -41,6 +40,7 @@ import com.hedvig.android.navigation.core.HedvigDeepLinkContainer
import com.hedvig.android.notification.badge.data.tab.TabNotificationBadgeService
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
Expand Down Expand Up @@ -197,20 +197,18 @@ private fun LogoutOnInvalidCredentialsEffect(
combine(
authTokenService.authStatus.onEach(authStatusLog).filterNotNull().distinctUntilChanged(),
demoManager.isDemoMode().distinctUntilChanged(),
) { authStatus: AuthStatus, isDemoMode: Boolean ->
authStatus to isDemoMode
}.collect { (authStatus, isDemoMode) ->
val navBackStackEntry: NavBackStackEntry = hedvigAppState.navController.currentBackStackEntryFlow.first()
hedvigAppState.navController.currentBackStackEntryFlow,
) { authStatus: AuthStatus, isDemoMode: Boolean, navBackStackEntry ->
val isLoggedOut = navBackStackEntry.destination.hierarchy.any { navDestination ->
navDestination.typedHasRoute<LoginDestination>()
}
if (isLoggedOut) {
return@collect
return@combine
}
if (!isDemoMode && authStatus !is AuthStatus.LoggedIn) {
hedvigAppState.navigateToLoggedOut()
}
}
}.collect()
}
}
}

0 comments on commit 59a3eff

Please sign in to comment.