Skip to content

Commit

Permalink
fix(e2ei): loading e2ei state during the app initialisation (#2755)
Browse files Browse the repository at this point in the history
Co-authored-by: Mojtaba Chenani <[email protected]>
Co-authored-by: Mohamad Jaara <[email protected]>
  • Loading branch information
3 people authored Mar 4, 2024
1 parent 1875400 commit f54e896
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
25 changes: 8 additions & 17 deletions app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,19 @@ class WireActivityViewModel @Inject constructor(
private val _observeSyncFlowState: MutableStateFlow<SyncState?> = MutableStateFlow(null)
val observeSyncFlowState: StateFlow<SyncState?> = _observeSyncFlowState

private val _observeE2EIState: MutableStateFlow<Boolean?> = MutableStateFlow(null)
private val observeE2EIState: StateFlow<Boolean?> = _observeE2EIState
private val observeE2EIState = observeUserId
.flatMapLatest {
it?.let { observeIfE2EIRequiredDuringLoginUseCaseProviderFactory.create(it).observeIfE2EIIsRequiredDuringLogin() }
?: flowOf(null)
}
.distinctUntilChanged()

init {
observeSyncState()
observeUpdateAppState()
observeNewClientState()
observeScreenshotCensoringConfigState()
observeAppThemeState()
observerE2EIState()
}

private fun observeAppThemeState() {
Expand All @@ -167,18 +170,6 @@ class WireActivityViewModel @Inject constructor(
}
}

fun observerE2EIState() {
viewModelScope.launch(dispatchers.io()) {
observeUserId
.flatMapLatest {
it?.let { observeIfE2EIRequiredDuringLoginUseCaseProviderFactory.create(it).observeIfE2EIIsRequiredDuringLogin() }
?: flowOf(null)
}
.distinctUntilChanged()
.collect { _observeE2EIState.emit(it) }
}
}

private fun observeSyncState() {
viewModelScope.launch(dispatchers.io()) {
observeUserId
Expand Down Expand Up @@ -434,8 +425,8 @@ class WireActivityViewModel @Inject constructor(

fun shouldLogIn(): Boolean = !hasValidCurrentSession()

fun blockedByE2EI(): Boolean {
return observeE2EIState.value == true
private fun blockedByE2EI(): Boolean = runBlocking {
observeE2EIState.first() ?: false
}

private fun hasValidCurrentSession(): Boolean = runBlocking {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,6 @@ class WireActivityViewModelTest {

private class Arrangement {

// TODO add tests for cases when observeIfE2EIIsRequiredDuringLogin emits semothing
private val observeIfE2EIIsRequiredDuringLogin = MutableSharedFlow<Boolean?>()

init {
// Tests setup
MockKAnnotations.init(this, relaxUnitFun = true)
Expand All @@ -614,7 +611,7 @@ class WireActivityViewModelTest {
coEvery { currentScreenManager.observeCurrentScreen(any()) } returns MutableStateFlow(CurrentScreen.SomeOther)
coEvery { globalDataStore.selectedThemeOptionFlow() } returns flowOf(ThemeOption.LIGHT)
coEvery { observeIfE2EIRequiredDuringLoginUseCaseProviderFactory.create(any()).observeIfE2EIIsRequiredDuringLogin() } returns
observeIfE2EIIsRequiredDuringLogin
flowOf(false)
}

@MockK
Expand Down Expand Up @@ -766,6 +763,7 @@ class WireActivityViewModelTest {

fun withCurrentScreen(currentScreenFlow: StateFlow<CurrentScreen>) = apply {
coEvery { currentScreenManager.observeCurrentScreen(any()) } returns currentScreenFlow
coEvery { coreLogic.getSessionScope(TEST_ACCOUNT_INFO.userId).observeIfE2EIRequiredDuringLogin() } returns flowOf(false)
}

suspend fun withScreenshotCensoringConfig(result: ObserveScreenshotCensoringConfigResult) = apply {
Expand Down

0 comments on commit f54e896

Please sign in to comment.