Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita73f19f

Browse files
authored
fix: home requirements navigation crashing [WPB-17263] (#3999)
1 parente35bdc4 commita73f19f

File tree

3 files changed

+54
-30
lines changed

3 files changed

+54
-30
lines changed

‎app/src/main/kotlin/com/wire/android/ui/home/HomeScreen.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import androidx.compose.ui.unit.min
5454
importandroidx.hilt.navigation.compose.hiltViewModel
5555
importandroidx.lifecycle.Lifecycle
5656
importandroidx.lifecycle.LifecycleEventObserver
57+
importandroidx.lifecycle.repeatOnLifecycle
5758
importcom.google.accompanist.navigation.material.ExperimentalMaterialNavigationApi
5859
importcom.ramcosta.composedestinations.DestinationsNavHost
5960
importcom.ramcosta.composedestinations.animations.defaults.RootNavGraphDefaultAnimations
@@ -122,8 +123,18 @@ fun HomeScreen(
122123
creationCallback = { it.create(ConversationFoldersStateArgs(null)) }
123124
)
124125
) {
125-
homeViewModel.checkRequirements { it.navigate(navigator::navigate) }
126126
val context=LocalContext.current
127+
val lifecycle= androidx.lifecycle.compose.LocalLifecycleOwner.current
128+
129+
homeViewModel.checkRequirements()
130+
131+
LaunchedEffect(Unit) {
132+
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
133+
homeViewModel.actions.collect {
134+
it.navigate(navigator::navigate)
135+
}
136+
}
137+
}
127138

128139
val homeScreenState= rememberHomeScreenState(navigator)
129140
val notificationsPermissionDeniedDialogState= rememberVisibilityState<PermissionPermanentlyDeniedDialogState>()

‎app/src/main/kotlin/com/wire/android/ui/home/HomeViewModel.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ import com.wire.kalium.logic.feature.legalhold.ObserveLegalHoldStateForSelfUserU
3838
importcom.wire.kalium.logic.feature.personaltoteamaccount.CanMigrateFromPersonalToTeamUseCase
3939
importcom.wire.kalium.logic.feature.user.ObserveSelfUserUseCase
4040
importdagger.hilt.android.lifecycle.HiltViewModel
41+
importkotlinx.coroutines.channels.BufferOverflow
42+
importkotlinx.coroutines.channels.Channel
4143
importkotlinx.coroutines.flow.MutableSharedFlow
4244
importkotlinx.coroutines.flow.collectLatest
4345
importkotlinx.coroutines.flow.first
4446
importkotlinx.coroutines.flow.firstOrNull
47+
importkotlinx.coroutines.flow.receiveAsFlow
4548
importkotlinx.coroutines.launch
4649
importjavax.inject.Inject
4750

@@ -64,6 +67,12 @@ class HomeViewModel @Inject constructor(
6467

6568
privateval selfUserFlow=MutableSharedFlow<SelfUser?>(replay=1)
6669

70+
privateval_actions=Channel<HomeRequirement>(
71+
capacity=Channel.BUFFERED,
72+
onBufferOverflow=BufferOverflow.DROP_OLDEST
73+
)
74+
internalval actions=_actions.receiveAsFlow()
75+
6776
init {
6877
observeSelfUser()
6978
observeLegalHoldStatus()
@@ -114,21 +123,21 @@ class HomeViewModel @Inject constructor(
114123
}
115124
}
116125

117-
funcheckRequirements(onRequirement: (HomeRequirement)->Unit) {
126+
funcheckRequirements() {
118127
viewModelScope.launch {
119128
val selfUser= selfUserFlow.firstOrNull()?:return@launch
120129
when {
121130
shouldTriggerMigrationForUser(selfUser.id)->// check if the user needs to be migrated from scala app
122-
onRequirement(HomeRequirement.Migration(selfUser.id))
131+
_actions.send(HomeRequirement.Migration(selfUser.id))
123132

124133
needsToRegisterClient()->// check if the client needs to be registered
125-
onRequirement(HomeRequirement.RegisterDevice)
134+
_actions.send(HomeRequirement.RegisterDevice)
126135

127136
!dataStore.initialSyncCompleted.first()->// check if the initial sync needs to be completed
128-
onRequirement(HomeRequirement.InitialSync)
137+
_actions.send(HomeRequirement.InitialSync)
129138

130139
selfUser.handle.isNullOrEmpty()->// check if the user handle needs to be set
131-
onRequirement(HomeRequirement.CreateAccountUsername)
140+
_actions.send(HomeRequirement.CreateAccountUsername)
132141

133142
// check if the "welcome to the new app" screen needs to be displayed
134143
shouldDisplayWelcomeToARScreen()->

‎app/src/test/kotlin/com/wire/android/ui/home/HomeViewModelTest.kt

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
packagecom.wire.android.ui.home
1919

2020
importandroidx.lifecycle.SavedStateHandle
21+
importapp.cash.turbine.test
2122
importcom.wire.android.config.CoroutineTestExtension
2223
importcom.wire.android.datastore.GlobalDataStore
2324
importcom.wire.android.datastore.UserDataStore
@@ -33,8 +34,6 @@ import com.wire.kalium.logic.feature.user.ObserveSelfUserUseCase
3334
importio.mockk.MockKAnnotations
3435
importio.mockk.coEvery
3536
importio.mockk.impl.annotations.MockK
36-
importio.mockk.impl.annotations.RelaxedMockK
37-
importio.mockk.verify
3837
importkotlinx.coroutines.ExperimentalCoroutinesApi
3938
importkotlinx.coroutines.flow.Flow
4039
importkotlinx.coroutines.flow.MutableStateFlow
@@ -102,11 +101,13 @@ class HomeViewModelTest {
102101
val (arrangement, viewModel)=Arrangement()
103102
.withShouldTriggerMigrationForUserReturning(true)
104103
.arrange()
105-
// when
106-
viewModel.checkRequirements(arrangement.onRequirement)
107-
advanceUntilIdle()
108-
// then
109-
verify { arrangement.onRequirement(HomeRequirement.Migration(TestUser.SELF_USER.id)) }
104+
viewModel.actions.test {
105+
// when
106+
viewModel.checkRequirements()
107+
advanceUntilIdle()
108+
// then
109+
assertEquals(HomeRequirement.Migration(TestUser.SELF_USER.id), expectMostRecentItem())
110+
}
110111
}
111112

112113
@Test
@@ -116,10 +117,12 @@ class HomeViewModelTest {
116117
.withShouldTriggerMigrationForUserReturning(false)
117118
.withNeedsToRegisterClientReturning(true)
118119
.arrange()
119-
// when
120-
viewModel.checkRequirements(arrangement.onRequirement)
121-
// then
122-
verify { arrangement.onRequirement(HomeRequirement.RegisterDevice) }
120+
viewModel.actions.test {
121+
// when
122+
viewModel.checkRequirements()
123+
// then
124+
assertEquals(HomeRequirement.RegisterDevice, expectMostRecentItem())
125+
}
123126
}
124127

125128
@Test
@@ -130,10 +133,12 @@ class HomeViewModelTest {
130133
.withNeedsToRegisterClientReturning(false)
131134
.withInitialSyncCompletedReturning(flowOf(false))
132135
.arrange()
133-
// when
134-
viewModel.checkRequirements(arrangement.onRequirement)
135-
// then
136-
verify { arrangement.onRequirement(HomeRequirement.InitialSync) }
136+
viewModel.actions.test {
137+
// when
138+
viewModel.checkRequirements()
139+
// then
140+
assertEquals(HomeRequirement.InitialSync, expectMostRecentItem())
141+
}
137142
}
138143

139144
@Test
@@ -145,10 +150,12 @@ class HomeViewModelTest {
145150
.withInitialSyncCompletedReturning(flowOf(true))
146151
.withSelfUser(flowOf(TestUser.SELF_USER.copy(handle=null)))
147152
.arrange()
148-
// when
149-
viewModel.checkRequirements(arrangement.onRequirement)
150-
// then
151-
verify { arrangement.onRequirement(HomeRequirement.CreateAccountUsername) }
153+
viewModel.actions.test {
154+
// when
155+
viewModel.checkRequirements()
156+
// then
157+
assertEquals(HomeRequirement.CreateAccountUsername, expectMostRecentItem())
158+
}
152159
}
153160

154161
@Test
@@ -163,7 +170,7 @@ class HomeViewModelTest {
163170
.withWelcomeScreenPresentedReturning(false)
164171
.arrange()
165172
// when
166-
viewModel.checkRequirements(arrangement.onRequirement)
173+
viewModel.checkRequirements()
167174
// then
168175
assertEquals(true, viewModel.homeState.shouldDisplayWelcomeMessage)
169176
}
@@ -180,7 +187,7 @@ class HomeViewModelTest {
180187
.withWelcomeScreenPresentedReturning(true)
181188
.arrange()
182189
// when
183-
viewModel.checkRequirements(arrangement.onRequirement)
190+
viewModel.checkRequirements()
184191
// then
185192
assertEquals(false, viewModel.homeState.shouldDisplayWelcomeMessage)
186193
}
@@ -211,9 +218,6 @@ class HomeViewModelTest {
211218
@MockK
212219
lateinitvar canMigrateFromPersonalToTeam:CanMigrateFromPersonalToTeamUseCase
213220

214-
@RelaxedMockK
215-
lateinitvar onRequirement: (HomeRequirement)->Unit
216-
217221
privateval viewModel by lazy {
218222
HomeViewModel(
219223
savedStateHandle= savedStateHandle,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp