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

feat: connect to upgrade-personal-to-team API #WPB-11992 #3625

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
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
8 changes: 8 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 @@ -492,4 +492,12 @@ class UseCaseModule {
@Provides
fun provideSendFCMTokenToAPIUseCase(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) =
coreLogic.getSessionScope(currentAccount).debug.sendFCMTokenToServer

@ViewModelScoped
@Provides
fun provideMigrateFromPersonalToTeamUseCase(
@KaliumCoreLogic coreLogic: CoreLogic,
@CurrentAccount currentAccount: UserId
) =
coreLogic.getSessionScope(currentAccount).migrateFromPersonalToTeam
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package com.wire.android.ui.userprofile.teammigration

import androidx.compose.foundation.text.input.TextFieldState
import com.wire.kalium.logic.CoreFailure

data class TeamMigrationState(
val teamNameTextState: TextFieldState = TextFieldState(),
val shouldShowMigrationLeaveDialog: Boolean = false
val shouldShowMigrationLeaveDialog: Boolean = false,
val migrationFailure: CoreFailure? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wire.android.feature.analytics.AnonymousAnalyticsManager
import com.wire.android.feature.analytics.model.AnalyticsEvent
import com.wire.kalium.logic.CoreFailure
import com.wire.kalium.logic.feature.team.migration.MigrateFromPersonalToTeamResult
import com.wire.kalium.logic.feature.team.migration.MigrateFromPersonalToTeamUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class TeamMigrationViewModel @Inject constructor(
private val anonymousAnalyticsManager: AnonymousAnalyticsManager
private val anonymousAnalyticsManager: AnonymousAnalyticsManager,
private val teamMigrationUseCase: MigrateFromPersonalToTeamUseCase
) : ViewModel() {

var teamMigrationState by mutableStateOf(TeamMigrationState())
Expand Down Expand Up @@ -81,4 +87,32 @@ class TeamMigrationViewModel @Inject constructor(
)
)
}

fun postTeamMigration(
onSuccess: (teamId: String, teamName: String) -> Unit,
) {
viewModelScope.launch {
teamMigrationUseCase.invoke(
teamMigrationState.teamNameTextState.text.toString(),
).let { result ->
when (result) {
is MigrateFromPersonalToTeamResult.Success -> {
onSuccess(result.teamId, result.teamName)
}

is MigrateFromPersonalToTeamResult.Error -> {
onMigrationFailure(result.failure)
}
}
}
}
}

fun failureHandled() {
teamMigrationState = teamMigrationState.copy(migrationFailure = null)
}

private fun onMigrationFailure(failure: CoreFailure) {
teamMigrationState = teamMigrationState.copy(migrationFailure = failure)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ import com.wire.android.navigation.style.SlideNavigationAnimation
import com.wire.android.ui.common.WireCheckbox
import com.wire.android.ui.common.colorsScheme
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.common.error.CoreFailureErrorDialog
import com.wire.android.ui.destinations.TeamMigrationDoneStepScreenDestination
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireTypography
import com.wire.android.ui.userprofile.teammigration.PersonalToTeamMigrationNavGraph
import com.wire.android.ui.userprofile.teammigration.TeamMigrationState
import com.wire.android.ui.userprofile.teammigration.TeamMigrationViewModel
import com.wire.android.ui.userprofile.teammigration.common.BottomLineButtons
import com.wire.android.ui.userprofile.teammigration.common.BulletList
Expand All @@ -66,21 +68,43 @@ fun TeamMigrationConfirmationStepScreen(
navigator: DestinationsNavigator,
teamMigrationViewModel: TeamMigrationViewModel
) {
val state = remember { teamMigrationViewModel.teamMigrationState }

TeamMigrationConfirmationStepScreenContent(
onContinueButtonClicked = {
// TODO: call the API to migrate the user to the team, if successful navigate to next screen
navigator.navigate(TeamMigrationDoneStepScreenDestination)
teamMigrationViewModel.postTeamMigration(
onSuccess = { _, _ ->
navigator.navigate(TeamMigrationDoneStepScreenDestination)
},
)
},
onBackPressed = {
navigator.popBackStack()
}
)

handleErrors(state, teamMigrationViewModel)

LaunchedEffect(Unit) {
teamMigrationViewModel.sendPersonalTeamCreationFlowStartedEvent(3)
}
}

@Composable
private fun handleErrors(
teamMigrationState: TeamMigrationState,
teamMigrationViewModel: TeamMigrationViewModel
) {
val failure = teamMigrationState.migrationFailure ?: return
// TODO handle error WPB-14281
CoreFailureErrorDialog(
coreFailure = failure,
onDialogDismiss = {
teamMigrationViewModel.failureHandled()
}
)
}

@Composable
private fun TeamMigrationConfirmationStepScreenContent(
modifier: Modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.wire.android.ui.userprofile.teammigration

import com.wire.android.feature.analytics.AnonymousAnalyticsManager
import com.wire.android.feature.analytics.model.AnalyticsEvent
import com.wire.kalium.logic.feature.team.migration.MigrateFromPersonalToTeamUseCase
import io.mockk.MockKAnnotations
import io.mockk.impl.annotations.MockK
import io.mockk.verify
Expand Down Expand Up @@ -162,12 +163,16 @@ class TeamMigrationViewModelTest {
@MockK
lateinit var anonymousAnalyticsManager: AnonymousAnalyticsManager

@MockK
lateinit var teamMigrationUseCase: MigrateFromPersonalToTeamUseCase

init {
MockKAnnotations.init(this, relaxUnitFun = true)
}

fun arrange() = this to TeamMigrationViewModel(
anonymousAnalyticsManager = anonymousAnalyticsManager
anonymousAnalyticsManager = anonymousAnalyticsManager,
teamMigrationUseCase = teamMigrationUseCase,
)
}
}
2 changes: 1 addition & 1 deletion kalium
Submodule kalium updated 87 files
+4 −2 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/event/Event.kt
+189 −97 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/user/UserRepository.kt
+16 −10 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt
+54 −0 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/team/migration/MigrateFromPersonalToTeamUseCase.kt
+24 −6 logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/NewConversationEventHandler.kt
+3 −3 logic/src/commonTest/kotlin/com/wire/kalium/logic/data/client/ClientRepositoryTest.kt
+0 −42 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/client/ClientMocks.kt
+39 −3 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/ClientResponseJson.kt
+2 −3 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/ListOfClientsResponseJson.kt
+2 −2 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/NotificationEventsResponseJson.kt
+107 −64 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt
+27 −0 network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/CreateUserTeamDTO.kt
+40 −0 ...rk-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/CapabilitiesDeserializer.kt
+3 −1 network-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/client/ClientDTO.kt
+3 −0 ...-model/src/commonMain/kotlin/com/wire/kalium/network/api/authenticated/conversation/ConversationResponse.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/BackendMetaDataUtil.kt
+1 −3 network/src/commonMain/kotlin/com/wire/kalium/network/KaliumHttpLogger.kt
+12 −12 network/src/commonMain/kotlin/com/wire/kalium/network/KaliumKtorCustomLogging.kt
+30 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/UpgradePersonalToTeamApi.kt
+11 −15 network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/conversation/ConversationApi.kt
+1 −3 network/src/commonMain/kotlin/com/wire/kalium/network/api/base/authenticated/notification/NotificationApi.kt
+31 −18 network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/ConversationApiV0.kt
+33 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v0/authenticated/UpgradePersonalToTeamApiV0.kt
+7 −0 ...ain/kotlin/com/wire/kalium/network/api/v0/authenticated/networkContainer/AuthenticatedNetworkContainerV0.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/PreKeyApiV2.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/PropertiesApiV2.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v2/authenticated/UpgradePersonalToTeamApiV2.kt
+7 −0 ...ain/kotlin/com/wire/kalium/network/api/v2/authenticated/networkContainer/AuthenticatedNetworkContainerV2.kt
+0 −10 network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/ConversationApiV3.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/PropertiesApiV3.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v3/authenticated/UpgradePersonalToTeamApiV3.kt
+7 −0 ...ain/kotlin/com/wire/kalium/network/api/v3/authenticated/networkContainer/AuthenticatedNetworkContainerV3.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/AccessTokenApiV4.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/NotificationApiV4.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/PropertiesApiV4.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v4/authenticated/UpgradePersonalToTeamApiV4.kt
+7 −0 ...ain/kotlin/com/wire/kalium/network/api/v4/authenticated/networkContainer/AuthenticatedNetworkContainerV4.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/AccessTokenApiV5.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/NotificationApiV5.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v5/authenticated/UpgradePersonalToTeamApiV5.kt
+7 −0 ...ain/kotlin/com/wire/kalium/network/api/v5/authenticated/networkContainer/AuthenticatedNetworkContainerV5.kt
+2 −2 network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/AccessTokenApiV6.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/E2EIApiV6.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/KeyPackageApiV6.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/MLSMessageApiV6.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/MLSPublicKeyApiV6.kt
+1 −1 network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/NotificationApiV6.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v6/authenticated/UpgradePersonalToTeamApiV6.kt
+8 −0 ...ain/kotlin/com/wire/kalium/network/api/v6/authenticated/networkContainer/AuthenticatedNetworkContainerV6.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AccessTokenApiV7.kt
+28 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/AssetApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/CallApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ClientApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ConnectionApiV7.kt
+48 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/ConversationApiV7.kt
+25 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/E2EIApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/FeatureConfigApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/KeyPackageApiV7.kt
+28 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/LogoutApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSMessageApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MLSPublicKeyApiV7.kt
+28 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/MessageApiV7.kt
+30 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/NotificationApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/PreKeyApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/PropertiesApiV7.kt
+28 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/SelfApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/TeamsApiV7.kt
+54 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UpgradePersonalToTeamApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UserDetailsApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/authenticated/UserSearchApiV7.kt
+158 −0 ...ain/kotlin/com/wire/kalium/network/api/v7/authenticated/networkContainer/AuthenticatedNetworkContainerV7.kt
+25 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/DomainLookupApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/LoginApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/RegisterApiV7.kt
+26 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/SSOLoginApiV7.kt
+25 −0 network/src/commonMain/kotlin/com/wire/kalium/network/api/v7/unauthenticated/VerificationCodeApiV7.kt
+85 −0 ...kotlin/com/wire/kalium/network/api/v7/unauthenticated/networkContainer/UnauthenticatedNetworkContainerV7.kt
+22 −0 network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/AuthenticatedNetworkContainer.kt
+13 −4 network/src/commonMain/kotlin/com/wire/kalium/network/networkContainer/UnauthenticatedNetworkContainer.kt
+0 −1 network/src/commonMain/kotlin/com/wire/kalium/network/utils/ObfuscateUtil.kt
+41 −0 network/src/commonTest/kotlin/com/wire/kalium/api/authenticated/client/ClientDTOSerializationTest.kt
+64 −0 network/src/commonTest/kotlin/com/wire/kalium/api/v7/ConversationApiV7Test.kt
+10 −22 persistence/src/commonMain/db_user/com/wire/kalium/persistence/ConversationDetailsWithEvents.sq
+4 −12 persistence/src/commonMain/db_user/com/wire/kalium/persistence/MessageDrafts.sq
+0 −80 persistence/src/commonMain/db_user/migrations/89.sqm
+7 −14 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/draft/MessageDraftDAOImpl.kt
+0 −42 persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/message/draft/MessageDraftDAOTest.kt
Loading