From d092f29c934068ec167f0ddad45cc1a6524d7ba6 Mon Sep 17 00:00:00 2001 From: AndroidBob Date: Fri, 8 Dec 2023 11:49:57 +0100 Subject: [PATCH] fix: App lock does not show up after fresh install (WPB-5609) (#2501) Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Oussama Hassine --- .../feature/ObserveAppLockConfigUseCase.kt | 51 +++++++++---------- .../ObserveAppLockConfigUseCaseTest.kt | 15 +++--- kalium | 2 +- 3 files changed, 32 insertions(+), 36 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/feature/ObserveAppLockConfigUseCase.kt b/app/src/main/kotlin/com/wire/android/feature/ObserveAppLockConfigUseCase.kt index 191a38d14b0..58465bb1964 100644 --- a/app/src/main/kotlin/com/wire/android/feature/ObserveAppLockConfigUseCase.kt +++ b/app/src/main/kotlin/com/wire/android/feature/ObserveAppLockConfigUseCase.kt @@ -21,7 +21,6 @@ import com.wire.android.datastore.GlobalDataStore import com.wire.android.di.KaliumCoreLogic import com.wire.kalium.logic.CoreLogic import com.wire.kalium.logic.feature.session.CurrentSessionResult -import com.wire.kalium.logic.feature.session.CurrentSessionUseCase import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.channelFlow import kotlinx.coroutines.flow.collectLatest @@ -34,39 +33,39 @@ import kotlin.time.Duration.Companion.seconds @Singleton class ObserveAppLockConfigUseCase @Inject constructor( private val globalDataStore: GlobalDataStore, - @KaliumCoreLogic private val coreLogic: CoreLogic, - private val currentSession: CurrentSessionUseCase + @KaliumCoreLogic private val coreLogic: CoreLogic ) { - operator fun invoke(): Flow = channelFlow { - when (val currentSession = currentSession()) { - is CurrentSessionResult.Failure -> { - send(AppLockConfig.Disabled(DEFAULT_APP_LOCK_TIMEOUT)) - } + coreLogic.getGlobalScope().session.currentSessionFlow().collectLatest { sessionResult -> + when (sessionResult) { + is CurrentSessionResult.Failure -> { + send(AppLockConfig.Disabled(DEFAULT_APP_LOCK_TIMEOUT)) + } - is CurrentSessionResult.Success -> { - val userId = currentSession.accountInfo.userId - val appLockTeamFeatureConfigFlow = - coreLogic.getSessionScope(userId).appLockTeamFeatureConfigObserver + is CurrentSessionResult.Success -> { + val userId = sessionResult.accountInfo.userId + val appLockTeamFeatureConfigFlow = + coreLogic.getSessionScope(userId).appLockTeamFeatureConfigObserver - appLockTeamFeatureConfigFlow().combineTransform( - globalDataStore.isAppLockPasscodeSetFlow() - ) { teamAppLockConfig, isAppLockConfigured -> - when { - isAppLockConfigured -> { - emit(AppLockConfig.Enabled(teamAppLockConfig?.timeout ?: DEFAULT_APP_LOCK_TIMEOUT)) - } + appLockTeamFeatureConfigFlow().combineTransform( + globalDataStore.isAppLockPasscodeSetFlow() + ) { teamAppLockConfig, isAppLockConfigured -> + when { + isAppLockConfigured -> { + emit(AppLockConfig.Enabled(teamAppLockConfig?.timeout ?: DEFAULT_APP_LOCK_TIMEOUT)) + } - teamAppLockConfig != null && teamAppLockConfig.isEnforced -> { - emit(AppLockConfig.EnforcedByTeam(teamAppLockConfig.timeout)) - } + teamAppLockConfig != null && teamAppLockConfig.isEnforced -> { + emit(AppLockConfig.EnforcedByTeam(teamAppLockConfig.timeout)) + } - else -> { - emit(AppLockConfig.Disabled(teamAppLockConfig?.timeout ?: DEFAULT_APP_LOCK_TIMEOUT)) + else -> { + emit(AppLockConfig.Disabled(teamAppLockConfig?.timeout ?: DEFAULT_APP_LOCK_TIMEOUT)) + } } + }.collectLatest { + send(it) } - }.collectLatest { - send(it) } } } diff --git a/app/src/test/kotlin/com/wire/android/feature/ObserveAppLockConfigUseCaseTest.kt b/app/src/test/kotlin/com/wire/android/feature/ObserveAppLockConfigUseCaseTest.kt index ce628f0544b..170f58a67b3 100644 --- a/app/src/test/kotlin/com/wire/android/feature/ObserveAppLockConfigUseCaseTest.kt +++ b/app/src/test/kotlin/com/wire/android/feature/ObserveAppLockConfigUseCaseTest.kt @@ -20,13 +20,12 @@ package com.wire.android.feature import app.cash.turbine.test import com.wire.android.datastore.GlobalDataStore import com.wire.kalium.logic.CoreLogic +import com.wire.kalium.logic.configuration.AppLockTeamConfig import com.wire.kalium.logic.data.auth.AccountInfo import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.feature.UserSessionScope -import com.wire.kalium.logic.configuration.AppLockTeamConfig import com.wire.kalium.logic.feature.applock.AppLockTeamFeatureConfigObserver import com.wire.kalium.logic.feature.session.CurrentSessionResult -import com.wire.kalium.logic.feature.session.CurrentSessionUseCase import io.mockk.MockKAnnotations import io.mockk.coEvery import io.mockk.every @@ -116,9 +115,6 @@ class ObserveAppLockConfigUseCaseTest { @MockK lateinit var globalDataStore: GlobalDataStore - @MockK - lateinit var currentSession: CurrentSessionUseCase - @MockK lateinit var coreLogic: CoreLogic @@ -131,8 +127,7 @@ class ObserveAppLockConfigUseCaseTest { val useCase by lazy { ObserveAppLockConfigUseCase( globalDataStore = globalDataStore, - coreLogic = coreLogic, - currentSession = currentSession + coreLogic = coreLogic ) } @@ -143,11 +138,13 @@ class ObserveAppLockConfigUseCaseTest { fun arrange() = this to useCase fun withNonValidSession() = apply { - coEvery { currentSession() } returns CurrentSessionResult.Failure.SessionNotFound + coEvery { coreLogic.getGlobalScope().session.currentSessionFlow() } returns + flowOf(CurrentSessionResult.Failure.SessionNotFound) } fun withValidSession() = apply { - coEvery { currentSession() } returns CurrentSessionResult.Success(accountInfo) + coEvery { coreLogic.getGlobalScope().session.currentSessionFlow() } returns + flowOf(CurrentSessionResult.Success(accountInfo)) } fun withTeamAppLockEnabled() = apply { diff --git a/kalium b/kalium index c2e46cdf3c5..8e02923b80b 160000 --- a/kalium +++ b/kalium @@ -1 +1 @@ -Subproject commit c2e46cdf3c55beb60b35596f961a729b7dede6c3 +Subproject commit 8e02923b80b6c6a32245f329ab668bb1e25c54f2