diff --git a/app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt b/app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt index b772a7ba015..f71d86aa684 100644 --- a/app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt +++ b/app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt @@ -261,6 +261,11 @@ class UseCaseModule { fun provideIsMLSEnabledUseCase(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) = coreLogic.getSessionScope(currentAccount).isMLSEnabled + @ViewModelScoped + @Provides + fun provideGetDefaultProtocol(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) = + coreLogic.getSessionScope(currentAccount).getDefaultProtocol + @ViewModelScoped @Provides fun provideIsE2EIEnabledUseCase(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) = diff --git a/app/src/main/kotlin/com/wire/android/ui/common/groupname/GroupConversationNameComponent.kt b/app/src/main/kotlin/com/wire/android/ui/common/groupname/GroupConversationNameComponent.kt index 177774939e3..215ed681280 100644 --- a/app/src/main/kotlin/com/wire/android/ui/common/groupname/GroupConversationNameComponent.kt +++ b/app/src/main/kotlin/com/wire/android/ui/common/groupname/GroupConversationNameComponent.kt @@ -124,7 +124,7 @@ fun GroupNameScreen( WireDropDown( items = ConversationOptions.Protocol.values().map { it.name }, - defaultItemIndex = ConversationOptions.Protocol.PROTEUS.ordinal, + defaultItemIndex = defaultProtocol.ordinal, selectedItemIndex = groupProtocol.ordinal, label = stringResource(R.string.protocol), modifier = Modifier diff --git a/app/src/main/kotlin/com/wire/android/ui/common/groupname/GroupMetadataState.kt b/app/src/main/kotlin/com/wire/android/ui/common/groupname/GroupMetadataState.kt index 0a3030db861..2105ee5b3dd 100644 --- a/app/src/main/kotlin/com/wire/android/ui/common/groupname/GroupMetadataState.kt +++ b/app/src/main/kotlin/com/wire/android/ui/common/groupname/GroupMetadataState.kt @@ -32,6 +32,7 @@ data class GroupMetadataState( val animatedGroupNameError: Boolean = false, val continueEnabled: Boolean = false, val mlsEnabled: Boolean = true, + val defaultProtocol: ConversationOptions.Protocol = ConversationOptions.Protocol.PROTEUS, val isLoading: Boolean = false, val error: NewGroupError = NewGroupError.None, val mode: GroupNameMode = GroupNameMode.CREATION, diff --git a/app/src/main/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModel.kt index 8a127d0c7e0..56207022ded 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModel.kt @@ -36,6 +36,7 @@ import com.wire.kalium.logic.data.conversation.ConversationOptions import com.wire.kalium.logic.data.id.ConversationId import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.feature.conversation.CreateGroupConversationUseCase +import com.wire.kalium.logic.feature.user.GetDefaultProtocolUseCase import com.wire.kalium.logic.feature.user.IsMLSEnabledUseCase import com.wire.kalium.logic.feature.user.IsSelfATeamMemberUseCase import dagger.hilt.android.lifecycle.HiltViewModel @@ -48,13 +49,22 @@ import javax.inject.Inject class NewConversationViewModel @Inject constructor( private val createGroupConversation: CreateGroupConversationUseCase, private val isSelfATeamMember: IsSelfATeamMemberUseCase, - isMLSEnabled: IsMLSEnabledUseCase + isMLSEnabled: IsMLSEnabledUseCase, + getDefaultProtocol: GetDefaultProtocolUseCase ) : ViewModel() { var newGroupState: GroupMetadataState by mutableStateOf( GroupMetadataState( - mlsEnabled = isMLSEnabled(), - ) + mlsEnabled = isMLSEnabled() + ).let { + val defaultProtocol = ConversationOptions + .Protocol + .fromSupportedProtocolToConversationOptionsProtocol(getDefaultProtocol()) + it.copy( + defaultProtocol = defaultProtocol, + groupProtocol = defaultProtocol + ) + } ) var groupOptionsState: GroupOptionState by mutableStateOf(GroupOptionState()) diff --git a/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelArrangement.kt b/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelArrangement.kt index 705efda75c5..997238d7e81 100644 --- a/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelArrangement.kt +++ b/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelArrangement.kt @@ -21,6 +21,7 @@ package com.wire.android.ui.home.newconversation import com.wire.android.config.mockUri import com.wire.android.framework.TestUser import com.wire.android.ui.home.newconversation.common.CreateGroupState +import com.wire.android.ui.home.newconversation.groupOptions.GroupOptionState import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.data.conversation.Conversation import com.wire.kalium.logic.data.conversation.MutedConversationStatus @@ -33,10 +34,12 @@ import com.wire.kalium.logic.data.user.UserAssetId import com.wire.kalium.logic.data.user.UserAvailabilityStatus import com.wire.kalium.logic.data.user.type.UserType import com.wire.kalium.logic.feature.conversation.CreateGroupConversationUseCase +import com.wire.kalium.logic.feature.user.GetDefaultProtocolUseCase import com.wire.kalium.logic.feature.user.IsMLSEnabledUseCase import com.wire.kalium.logic.feature.user.IsSelfATeamMemberUseCaseImpl import io.mockk.MockKAnnotations import io.mockk.coEvery +import io.mockk.every import io.mockk.impl.annotations.MockK internal class NewConversationViewModelArrangement { @@ -47,6 +50,7 @@ internal class NewConversationViewModelArrangement { // Default empty values coEvery { isMLSEnabledUseCase() } returns true coEvery { createGroupConversation(any(), any(), any()) } returns CreateGroupConversationUseCase.Result.Success(CONVERSATION) + every { getDefaultProtocol() } returns SupportedProtocol.PROTEUS } @MockK @@ -61,6 +65,13 @@ internal class NewConversationViewModelArrangement { @MockK(relaxed = true) lateinit var onGroupCreated: (ConversationId) -> Unit + @MockK + lateinit var getDefaultProtocol: GetDefaultProtocolUseCase + + private var groupOptionsState: GroupOptionState = GroupOptionState() + + private var createGroupState: CreateGroupState = CreateGroupState() + private companion object { val CONVERSATION_ID = ConversationId(value = "userId", domain = "domainId") val CONVERSATION = Conversation( @@ -128,14 +139,6 @@ internal class NewConversationViewModelArrangement { ) } - private val viewModel by lazy { - NewConversationViewModel( - createGroupConversation = createGroupConversation, - isMLSEnabled = isMLSEnabledUseCase, - isSelfATeamMember = isSelfTeamMember, - ) - } - fun withSyncFailureOnCreatingGroup() = apply { coEvery { createGroupConversation(any(), any(), any()) } returns CreateGroupConversationUseCase.Result.SyncFailure } @@ -147,7 +150,7 @@ internal class NewConversationViewModelArrangement { } fun withConflictingBackendsFailure() = apply { - viewModel.createGroupState = viewModel.createGroupState.copy( + createGroupState = createGroupState.copy( error = CreateGroupState.Error.ConflictedBackends(listOf("bella.wire.link", "foma.wire.link")) ) } @@ -157,14 +160,24 @@ internal class NewConversationViewModelArrangement { } fun withGuestEnabled(isGuestModeEnabled: Boolean) = apply { - viewModel.groupOptionsState = viewModel - .groupOptionsState - .copy(isAllowGuestEnabled = isGuestModeEnabled) + groupOptionsState = groupOptionsState.copy(isAllowGuestEnabled = isGuestModeEnabled) } fun withServicesEnabled(areServicesEnabled: Boolean) = apply { - viewModel.groupOptionsState = viewModel.groupOptionsState.copy(isAllowServicesEnabled = areServicesEnabled) + groupOptionsState = groupOptionsState.copy(isAllowServicesEnabled = areServicesEnabled) } - fun arrange() = this to viewModel + fun withDefaultProtocol(supportedProtocol: SupportedProtocol) = apply { + every { getDefaultProtocol() } returns supportedProtocol + } + + fun arrange() = this to NewConversationViewModel( + createGroupConversation = createGroupConversation, + isMLSEnabled = isMLSEnabledUseCase, + isSelfATeamMember = isSelfTeamMember, + getDefaultProtocol = getDefaultProtocol + ).also { + it.groupOptionsState = groupOptionsState + it.createGroupState = createGroupState + } } diff --git a/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelTest.kt index 77df786162a..04b6a75d253 100644 --- a/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/home/newconversation/NewConversationViewModelTest.kt @@ -24,11 +24,13 @@ import com.wire.android.config.CoroutineTestExtension import com.wire.android.ui.home.newconversation.common.CreateGroupState import com.wire.kalium.logic.data.conversation.Conversation import com.wire.kalium.logic.data.conversation.ConversationOptions +import com.wire.kalium.logic.data.user.SupportedProtocol import com.wire.kalium.logic.data.user.UserId import io.mockk.coVerify import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest +import org.amshove.kluent.internal.assertEquals import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldBeNull import org.junit.jupiter.api.Test @@ -143,4 +145,24 @@ class NewConversationViewModelTest { ) } } + + @Test + fun `given team settings is MLS default protocol, when getting default protocol, then result is MLS`() = runTest { + // given + val (_, viewModel) = NewConversationViewModelArrangement() + .withDefaultProtocol(SupportedProtocol.MLS) + .withIsSelfTeamMember(true) + .withServicesEnabled(false) + .withGuestEnabled(true) + .arrange() + + // when + val result = viewModel.newGroupState.defaultProtocol + + // then + assertEquals( + ConversationOptions.Protocol.MLS, + result + ) + } } diff --git a/kalium b/kalium index 701154449d9..5e527d3c7d0 160000 --- a/kalium +++ b/kalium @@ -1 +1 @@ -Subproject commit 701154449d9b615f928b69aad03ba840353a88d1 +Subproject commit 5e527d3c7d051468367d49a06f1d52aca1806e14