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: lateinit property selfUserId has not been initialized in ConversationInfoViewModel [WPB-14317] #3632

Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -52,20 +51,17 @@ 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()
val conversationId: QualifiedID = conversationNavArgs.conversationId

var conversationInfoViewState by mutableStateOf(ConversationInfoViewState(conversationId))

private lateinit var selfUserId: UserId

init {
getSelfUserId()
fetchMLSVerificationStatus()
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,9 +56,6 @@ class ConversationInfoViewModelArrangement {
@MockK
lateinit var observeConversationDetails: ObserveConversationDetailsUseCase

@MockK
lateinit var observerSelfUser: GetSelfUserUseCase

@MockK
lateinit var fetchConversationMLSVerificationStatus: FetchConversationMLSVerificationStatusUseCase

Expand All @@ -74,9 +70,9 @@ class ConversationInfoViewModelArrangement {
qualifiedIdMapper,
savedStateHandle,
observeConversationDetails,
observerSelfUser,
fetchConversationMLSVerificationStatus,
wireSessionImageLoader
wireSessionImageLoader,
selfUserId = TestUser.SELF_USER_ID,
)
}

Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -79,7 +77,6 @@ class ConversationInfoViewModelTest {
.withConversationDetailUpdate(
conversationDetails = oneToOneConversationDetails
)
.withSelfUser()
.arrange()
launch { viewModel.observeConversationDetails {} }.run {
advanceUntilIdle()
Expand All @@ -101,7 +98,6 @@ class ConversationInfoViewModelTest {
.withConversationDetailUpdate(
conversationDetails = oneToOneConversationDetails
)
.withSelfUser()
.arrange()
launch { viewModel.observeConversationDetails {} }.run {
advanceUntilIdle()
Expand All @@ -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()
Expand All @@ -140,7 +135,6 @@ class ConversationInfoViewModelTest {
.withConversationDetailUpdate(
conversationDetails = firstConversationDetails
)
.withSelfUser()
.arrange()
launch { viewModel.observeConversationDetails {} }.run {
advanceUntilIdle()
Expand Down Expand Up @@ -169,7 +163,6 @@ class ConversationInfoViewModelTest {
runTest {
// Given
val (_, viewModel) = ConversationInfoViewModelArrangement()
.withSelfUser()
.arrange()

// When - Then
Expand All @@ -185,7 +178,6 @@ class ConversationInfoViewModelTest {
.withConversationDetailUpdate(
conversationDetails = oneToOneConversationDetails
)
.withSelfUser()
.arrange()
launch { viewModel.observeConversationDetails {} }.run {
advanceUntilIdle()
Expand All @@ -202,7 +194,6 @@ class ConversationInfoViewModelTest {
val otherUserAvatar = conversationDetails.otherUser.previewPicture
val (_, viewModel) = ConversationInfoViewModelArrangement()
.withConversationDetailUpdate(conversationDetails = conversationDetails)
.withSelfUser()
.arrange()
launch { viewModel.observeConversationDetails {} }.run {
advanceUntilIdle()
Expand All @@ -220,7 +211,6 @@ class ConversationInfoViewModelTest {
val groupConversationDetails = mockConversationDetailsGroup("Conversation Name Goes Here")
val (_, viewModel) = ConversationInfoViewModelArrangement()
.withConversationDetailUpdate(conversationDetails = groupConversationDetails)
.withSelfUser()
.arrange()

// then
Expand All @@ -244,7 +234,6 @@ class ConversationInfoViewModelTest {
val groupConversationDetails = mockConversationDetailsGroup("Conversation Name Goes Here")
val (_, viewModel) = ConversationInfoViewModelArrangement()
.withConversationDetailUpdate(conversationDetails = groupConversationDetails)
.withSelfUser()
.arrange()

// then
Expand All @@ -268,7 +257,6 @@ class ConversationInfoViewModelTest {
val groupConversationDetails = mockConversationDetailsGroup("Conversation Name Goes Here")
val (_, viewModel) = ConversationInfoViewModelArrangement()
.withConversationDetailUpdate(conversationDetails = groupConversationDetails)
.withSelfUser()
.arrange()

// then
Expand All @@ -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
Expand All @@ -309,7 +296,6 @@ class ConversationInfoViewModelTest {
// Given
val (arrangement, viewModel) = ConversationInfoViewModelArrangement()
.withConversationDetailFailure(StorageFailure.DataNotFound)
.withSelfUser()
.arrange()
launch { viewModel.observeConversationDetails(arrangement.onNotFound) }.run {
advanceUntilIdle()
Expand Down
Loading