diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversations/info/ConversationInfoViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversations/info/ConversationInfoViewModel.kt index 3495deb7662..5e36411a498 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversations/info/ConversationInfoViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversations/info/ConversationInfoViewModel.kt @@ -25,6 +25,7 @@ import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import com.wire.android.R import com.wire.android.appLogger +import com.wire.android.di.CurrentAccount import com.wire.android.model.ImageAsset import com.wire.android.navigation.SavedStateViewModel import com.wire.android.ui.home.conversations.ConversationNavArgs @@ -40,9 +41,7 @@ import com.wire.kalium.logic.data.user.ConnectionState import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.feature.conversation.ObserveConversationDetailsUseCase import com.wire.kalium.logic.feature.e2ei.usecase.FetchConversationMLSVerificationStatusUseCase -import com.wire.kalium.logic.feature.user.GetSelfUserUseCase import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import javax.inject.Inject @@ -52,9 +51,9 @@ class ConversationInfoViewModel @Inject constructor( private val qualifiedIdMapper: QualifiedIdMapper, override val savedStateHandle: SavedStateHandle, private val observeConversationDetails: ObserveConversationDetailsUseCase, - private val observerSelfUser: GetSelfUserUseCase, private val fetchConversationMLSVerificationStatus: FetchConversationMLSVerificationStatusUseCase, private val wireSessionImageLoader: WireSessionImageLoader, + @CurrentAccount private val selfUserId: UserId, ) : SavedStateViewModel(savedStateHandle) { private val conversationNavArgs: ConversationNavArgs = savedStateHandle.navArgs() @@ -62,10 +61,7 @@ class ConversationInfoViewModel @Inject constructor( var conversationInfoViewState by mutableStateOf(ConversationInfoViewState(conversationId)) - private lateinit var selfUserId: UserId - init { - getSelfUserId() fetchMLSVerificationStatus() } @@ -75,12 +71,6 @@ class ConversationInfoViewModel @Inject constructor( } } - private fun getSelfUserId() { - viewModelScope.launch { - selfUserId = observerSelfUser().first().id - } - } - /* If this would be collected in the scope of this ViewModel (in `init` for instance) then there would be a race condition. [MessageComposerViewModel] handles the navigating back after removing a group and here it would navigate to home if the group diff --git a/app/src/test/kotlin/com/wire/android/ui/home/conversations/info/ConversationInfoViewModelArrangement.kt b/app/src/test/kotlin/com/wire/android/ui/home/conversations/info/ConversationInfoViewModelArrangement.kt index 397c3e3107b..931b5f6280d 100644 --- a/app/src/test/kotlin/com/wire/android/ui/home/conversations/info/ConversationInfoViewModelArrangement.kt +++ b/app/src/test/kotlin/com/wire/android/ui/home/conversations/info/ConversationInfoViewModelArrangement.kt @@ -32,7 +32,6 @@ import com.wire.kalium.logic.data.id.QualifiedIdMapper import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.feature.conversation.ObserveConversationDetailsUseCase import com.wire.kalium.logic.feature.e2ei.usecase.FetchConversationMLSVerificationStatusUseCase -import com.wire.kalium.logic.feature.user.GetSelfUserUseCase import io.mockk.MockKAnnotations import io.mockk.coEvery import io.mockk.every @@ -57,9 +56,6 @@ class ConversationInfoViewModelArrangement { @MockK lateinit var observeConversationDetails: ObserveConversationDetailsUseCase - @MockK - lateinit var observerSelfUser: GetSelfUserUseCase - @MockK lateinit var fetchConversationMLSVerificationStatus: FetchConversationMLSVerificationStatusUseCase @@ -74,9 +70,9 @@ class ConversationInfoViewModelArrangement { qualifiedIdMapper, savedStateHandle, observeConversationDetails, - observerSelfUser, fetchConversationMLSVerificationStatus, - wireSessionImageLoader + wireSessionImageLoader, + selfUserId = TestUser.SELF_USER_ID, ) } @@ -105,10 +101,6 @@ class ConversationInfoViewModelArrangement { coEvery { observeConversationDetails(any()) } returns flowOf(ObserveConversationDetailsUseCase.Result.Failure(failure)) } - suspend fun withSelfUser() = apply { - coEvery { observerSelfUser() } returns flowOf(TestUser.SELF_USER) - } - fun withMentionedUserId(id: UserId) = apply { every { qualifiedIdMapper.fromStringToQualifiedID(id.toString()) } returns id } diff --git a/app/src/test/kotlin/com/wire/android/ui/home/conversations/info/ConversationInfoViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/home/conversations/info/ConversationInfoViewModelTest.kt index d4243d490e4..76132e209bb 100644 --- a/app/src/test/kotlin/com/wire/android/ui/home/conversations/info/ConversationInfoViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/home/conversations/info/ConversationInfoViewModelTest.kt @@ -47,7 +47,6 @@ class ConversationInfoViewModelTest { val groupConversationDetails = mockConversationDetailsGroup("Conversation Name Goes Here") val (_, viewModel) = ConversationInfoViewModelArrangement() .withConversationDetailUpdate(conversationDetails = groupConversationDetails) - .withSelfUser() .withMentionedUserId(TestUser.SELF_USER.id) .arrange() // When @@ -62,7 +61,6 @@ class ConversationInfoViewModelTest { val groupConversationDetails = mockConversationDetailsGroup("Conversation Name Goes Here") val (_, viewModel) = ConversationInfoViewModelArrangement() .withConversationDetailUpdate(conversationDetails = groupConversationDetails) - .withSelfUser() .withMentionedUserId(TestUser.OTHER_USER.id) .arrange() // When @@ -79,7 +77,6 @@ class ConversationInfoViewModelTest { .withConversationDetailUpdate( conversationDetails = oneToOneConversationDetails ) - .withSelfUser() .arrange() launch { viewModel.observeConversationDetails {} }.run { advanceUntilIdle() @@ -101,7 +98,6 @@ class ConversationInfoViewModelTest { .withConversationDetailUpdate( conversationDetails = oneToOneConversationDetails ) - .withSelfUser() .arrange() launch { viewModel.observeConversationDetails {} }.run { advanceUntilIdle() @@ -117,7 +113,6 @@ class ConversationInfoViewModelTest { val groupConversationDetails = mockConversationDetailsGroup("Conversation Name Goes Here") val (_, viewModel) = ConversationInfoViewModelArrangement() .withConversationDetailUpdate(conversationDetails = groupConversationDetails) - .withSelfUser() .arrange() launch { viewModel.observeConversationDetails {} }.run { advanceUntilIdle() @@ -140,7 +135,6 @@ class ConversationInfoViewModelTest { .withConversationDetailUpdate( conversationDetails = firstConversationDetails ) - .withSelfUser() .arrange() launch { viewModel.observeConversationDetails {} }.run { advanceUntilIdle() @@ -169,7 +163,6 @@ class ConversationInfoViewModelTest { runTest { // Given val (_, viewModel) = ConversationInfoViewModelArrangement() - .withSelfUser() .arrange() // When - Then @@ -185,7 +178,6 @@ class ConversationInfoViewModelTest { .withConversationDetailUpdate( conversationDetails = oneToOneConversationDetails ) - .withSelfUser() .arrange() launch { viewModel.observeConversationDetails {} }.run { advanceUntilIdle() @@ -202,7 +194,6 @@ class ConversationInfoViewModelTest { val otherUserAvatar = conversationDetails.otherUser.previewPicture val (_, viewModel) = ConversationInfoViewModelArrangement() .withConversationDetailUpdate(conversationDetails = conversationDetails) - .withSelfUser() .arrange() launch { viewModel.observeConversationDetails {} }.run { advanceUntilIdle() @@ -220,7 +211,6 @@ class ConversationInfoViewModelTest { val groupConversationDetails = mockConversationDetailsGroup("Conversation Name Goes Here") val (_, viewModel) = ConversationInfoViewModelArrangement() .withConversationDetailUpdate(conversationDetails = groupConversationDetails) - .withSelfUser() .arrange() // then @@ -244,7 +234,6 @@ class ConversationInfoViewModelTest { val groupConversationDetails = mockConversationDetailsGroup("Conversation Name Goes Here") val (_, viewModel) = ConversationInfoViewModelArrangement() .withConversationDetailUpdate(conversationDetails = groupConversationDetails) - .withSelfUser() .arrange() // then @@ -268,7 +257,6 @@ class ConversationInfoViewModelTest { val groupConversationDetails = mockConversationDetailsGroup("Conversation Name Goes Here") val (_, viewModel) = ConversationInfoViewModelArrangement() .withConversationDetailUpdate(conversationDetails = groupConversationDetails) - .withSelfUser() .arrange() // then @@ -290,7 +278,6 @@ class ConversationInfoViewModelTest { fun `given Failure while getting an MLS conversation's verification status, then mlsVerificationStatus is null`() = runTest { // Given val (_, viewModel) = ConversationInfoViewModelArrangement() - .withSelfUser() .arrange() // then @@ -309,7 +296,6 @@ class ConversationInfoViewModelTest { // Given val (arrangement, viewModel) = ConversationInfoViewModelArrangement() .withConversationDetailFailure(StorageFailure.DataNotFound) - .withSelfUser() .arrange() launch { viewModel.observeConversationDetails(arrangement.onNotFound) }.run { advanceUntilIdle()