From 066dd98ca67a1ab958a3a8ab8a2a5e4703e4c6c1 Mon Sep 17 00:00:00 2001 From: Vitor Hugo Schwaab Date: Tue, 5 Dec 2023 11:00:27 -0300 Subject: [PATCH] feat(mls): reevaluate protocol on demand [WPB-5049] (#2502) --- .../di/accountScoped/ConversationModule.kt | 6 ++++ .../banner/ConversationBannerViewModel.kt | 5 ++++ .../banner/ConversationBannerViewModelTest.kt | 29 +++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/app/src/main/kotlin/com/wire/android/di/accountScoped/ConversationModule.kt b/app/src/main/kotlin/com/wire/android/di/accountScoped/ConversationModule.kt index 98896bc71d1..c5c74c61112 100644 --- a/app/src/main/kotlin/com/wire/android/di/accountScoped/ConversationModule.kt +++ b/app/src/main/kotlin/com/wire/android/di/accountScoped/ConversationModule.kt @@ -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 @@ -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 = diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversations/banner/ConversationBannerViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversations/banner/ConversationBannerViewModel.kt index d99a9c080ef..4caab05a79b 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversations/banner/ConversationBannerViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversations/banner/ConversationBannerViewModel.kt @@ -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 @@ -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(null) @@ -67,6 +69,9 @@ class ConversationBannerViewModel @Inject constructor( .flatMapLatest { observeConversationMembersByTypes(conversationId) } .collect(::handleConversationMemberTypes) } + viewModelScope.launch { + notifyConversationIsOpen(conversationId) + } } @Suppress("ComplexMethod") diff --git a/app/src/test/kotlin/com/wire/android/ui/home/conversations/banner/ConversationBannerViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/home/conversations/banner/ConversationBannerViewModelTest.kt index 69c5e1c163a..dc55750c57d 100644 --- a/app/src/test/kotlin/com/wire/android/ui/home/conversations/banner/ConversationBannerViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/home/conversations/banner/ConversationBannerViewModelTest.kt @@ -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 @@ -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 { @@ -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") @@ -126,6 +154,7 @@ private class Arrangement { every { savedStateHandle.navArgs() } returns ConversationNavArgs(conversationId = conversationId) // Default empty values coEvery { observeConversationMembersByTypesUseCase(any()) } returns flowOf() + coEvery { notifyConversationIsOpenUseCase(any()) } returns Unit } suspend fun withConversationParticipantsUserTypesUpdate(participants: List) = apply {