Skip to content

Commit

Permalink
feat: implement use case to get default conversation creation protoco…
Browse files Browse the repository at this point in the history
…l (WPB-5475) (#2725)

Co-authored-by: Alexandre Ferris <[email protected]>
  • Loading branch information
AndroidBob and alexandreferris authored Feb 21, 2024
1 parent 80aa6a3 commit ff529ed
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 19 deletions.
5 changes: 5 additions & 0 deletions app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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
}
Expand All @@ -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"))
)
}
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
}
}
2 changes: 1 addition & 1 deletion kalium
Submodule kalium updated 29 files
+14 −0 .github/technolinator.yml
+3 −0 logic/src/commonMain/kotlin/com/wire/kalium/logic/CoreFailure.kt
+1 −1 logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/E2EISettings.kt
+9 −0 logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/UserConfigRepository.kt
+11 −1 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/conversation/ConversationOptions.kt
+3 −4 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/e2ei/CertificateRevocationListRepository.kt
+26 −15 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/e2ei/E2EIRepository.kt
+13 −4 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/featureConfig/FeatureConfigMapper.kt
+1 −1 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/featureConfig/FeatureConfigModel.kt
+10 −4 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/session/SessionMapper.kt
+9 −3 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/session/token/AccessTokenRepository.kt
+1 −1 logic/src/commonMain/kotlin/com/wire/kalium/logic/di/MapperProvider.kt
+14 −7 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt
+3 −0 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/auth/LogoutUseCase.kt
+2 −2 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/featureConfig/SyncFeatureConfigsUseCase.kt
+6 −2 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/featureConfig/handler/E2EIConfigHandler.kt
+1 −11 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/session/token/AccessTokenRefresher.kt
+0 −1 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/session/token/AccessTokenRefresherFactory.kt
+44 −0 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/GetDefaultProtocolUseCase.kt
+21 −22 logic/src/commonMain/kotlin/com/wire/kalium/logic/network/SessionManagerImpl.kt
+2 −2 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/e2ei/CertificateRevocationListRepositoryTest.kt
+51 −3 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/e2ei/E2EIRepositoryTest.kt
+1 −7 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/session/SessionMapperTest.kt
+17 −1 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/auth/LogoutUseCaseTest.kt
+9 −6 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/session/token/AccessTokenRefresherTest.kt
+106 −0 logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/GetDefaultProtocolUseCaseTest.kt
+1 −1 ...rc/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/featureConfigs/FeatureConfigResponse.kt
+3 −1 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/client/AuthTokenStorage.kt
+13 −9 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/config/UserConfigStorage.kt

0 comments on commit ff529ed

Please sign in to comment.