Skip to content

Commit

Permalink
feat(mls): reevaluate protocol on demand [WPB-5049] (#2502)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorhugods authored Dec 5, 2023
1 parent 9489ca7 commit 066dd98
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.wire.kalium.logic.feature.conversation.GetOneToOneConversationUseCase
import com.wire.kalium.logic.feature.conversation.GetOrCreateOneToOneConversationUseCase
import com.wire.kalium.logic.feature.conversation.JoinConversationViaCodeUseCase
import com.wire.kalium.logic.feature.conversation.LeaveConversationUseCase
import com.wire.kalium.logic.feature.conversation.NotifyConversationIsOpenUseCase
import com.wire.kalium.logic.feature.conversation.ObserveArchivedUnreadConversationsCountUseCase
import com.wire.kalium.logic.feature.conversation.ObserveConversationDetailsUseCase
import com.wire.kalium.logic.feature.conversation.ObserveConversationInteractionAvailabilityUseCase
Expand Down Expand Up @@ -91,6 +92,11 @@ class ConversationModule {
fun provideObserveConversationDetailsUseCase(conversationScope: ConversationScope): ObserveConversationDetailsUseCase =
conversationScope.observeConversationDetails

@ViewModelScoped
@Provides
fun provideNotifyConversationIsOpenUseCase(conversationScope: ConversationScope): NotifyConversationIsOpenUseCase =
conversationScope.notifyConversationIsOpen

@ViewModelScoped
@Provides
fun provideDeleteTeamConversationUseCase(conversationScope: ConversationScope): DeleteTeamConversationUseCase =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.data.conversation.ConversationDetails
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.data.user.type.UserType
import com.wire.kalium.logic.feature.conversation.NotifyConversationIsOpenUseCase
import com.wire.kalium.logic.feature.conversation.ObserveConversationDetailsUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand All @@ -48,6 +49,7 @@ class ConversationBannerViewModel @Inject constructor(
override val savedStateHandle: SavedStateHandle,
private val observeConversationMembersByTypes: ObserveConversationMembersByTypesUseCase,
private val observeConversationDetails: ObserveConversationDetailsUseCase,
private val notifyConversationIsOpen: NotifyConversationIsOpenUseCase,
) : SavedStateViewModel(savedStateHandle) {

var bannerState by mutableStateOf<UIText?>(null)
Expand All @@ -67,6 +69,9 @@ class ConversationBannerViewModel @Inject constructor(
.flatMapLatest { observeConversationMembersByTypes(conversationId) }
.collect(::handleConversationMemberTypes)
}
viewModelScope.launch {
notifyConversationIsOpen(conversationId)
}
}

@Suppress("ComplexMethod")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ import com.wire.android.ui.home.conversations.banner.usecase.ObserveConversation
import com.wire.android.ui.navArgs
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.user.type.UserType
import com.wire.kalium.logic.feature.conversation.NotifyConversationIsOpenUseCase
import com.wire.kalium.logic.feature.conversation.ObserveConversationDetailsUseCase
import io.mockk.MockKAnnotations
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import io.mockk.impl.annotations.MockK
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down Expand Up @@ -97,6 +99,28 @@ class ConversationBannerViewModelTest {
awaitComplete()
}
}

@Test
fun givenGroupConversation_whenInitialisingViewModel_thenShouldCallNotifyConversationIsOpen() = runTest {
val (arrangement, _) = Arrangement()
.withGroupConversation()
.arrange()

coVerify(exactly = 1) {
arrangement.notifyConversationIsOpenUseCase(arrangement.conversationId)
}
}

@Test
fun givenOneOnOneConversation_whenInitialisingViewModel_thenShouldCallNotifyConversationIsOpen() = runTest {
val (arrangement, _) = Arrangement()
.withOneOnOneConversation()
.arrange()

coVerify(exactly = 1) {
arrangement.notifyConversationIsOpenUseCase(arrangement.conversationId)
}
}
}

private class Arrangement {
Expand All @@ -110,11 +134,15 @@ private class Arrangement {
@MockK
lateinit var observeConversationDetailsUseCase: ObserveConversationDetailsUseCase

@MockK
lateinit var notifyConversationIsOpenUseCase: NotifyConversationIsOpenUseCase

private val viewModel by lazy {
ConversationBannerViewModel(
savedStateHandle,
observeConversationMembersByTypesUseCase,
observeConversationDetailsUseCase,
notifyConversationIsOpenUseCase
)
}
val conversationId = ConversationId("some-dummy-value", "some.dummy.domain")
Expand All @@ -126,6 +154,7 @@ private class Arrangement {
every { savedStateHandle.navArgs<ConversationNavArgs>() } returns ConversationNavArgs(conversationId = conversationId)
// Default empty values
coEvery { observeConversationMembersByTypesUseCase(any()) } returns flowOf()
coEvery { notifyConversationIsOpenUseCase(any()) } returns Unit
}

suspend fun withConversationParticipantsUserTypesUpdate(participants: List<UserType>) = apply {
Expand Down

0 comments on commit 066dd98

Please sign in to comment.