Skip to content

Commit

Permalink
fix: App lock does not show up after fresh install (WPB-5609) (#2501)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Oussama Hassine <[email protected]>
  • Loading branch information
3 people authored Dec 8, 2023
1 parent 4bb97eb commit d092f29
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<AppLockConfig> = 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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -116,9 +115,6 @@ class ObserveAppLockConfigUseCaseTest {
@MockK
lateinit var globalDataStore: GlobalDataStore

@MockK
lateinit var currentSession: CurrentSessionUseCase

@MockK
lateinit var coreLogic: CoreLogic

Expand All @@ -131,8 +127,7 @@ class ObserveAppLockConfigUseCaseTest {
val useCase by lazy {
ObserveAppLockConfigUseCase(
globalDataStore = globalDataStore,
coreLogic = coreLogic,
currentSession = currentSession
coreLogic = coreLogic
)
}

Expand All @@ -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 {
Expand Down

0 comments on commit d092f29

Please sign in to comment.