Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(e2ei): loading e2ei state during the app initialisation #2755

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)

Check warning on line 151 in app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivityViewModel.kt#L151

Added line #L151 was not covered by tests
}
.distinctUntilChanged()

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

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

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 @@

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
Loading