Skip to content

Commit

Permalink
feat: Use enroll mls use case (WPB-5756) (#2514)
Browse files Browse the repository at this point in the history
  • Loading branch information
borichellow authored Dec 13, 2023
1 parent c5b8aa5 commit 961efb4
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.wire.kalium.logic.feature.e2ei.usecase.E2EIEnrollmentResult
import com.wire.kalium.logic.feature.e2ei.usecase.EnrollE2EIUseCase
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.functional.fold
import com.wire.kalium.logic.functional.map
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -62,10 +61,10 @@ class GetE2EICertificateUseCase @Inject constructor(
scope.launch {
when (oAuthResult) {
is OAuthUseCase.OAuthResult.Success -> {
enrollE2EI.finalizeEnrollment(
enrollmentResultHandler(enrollE2EI.finalizeEnrollment(
oAuthResult.idToken,
initialEnrollmentResult
).map { enrollmentResultHandler(Either.Right(it)) }
))
}

is OAuthUseCase.OAuthResult.Failed -> {
Expand Down
20 changes: 18 additions & 2 deletions app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
Expand All @@ -70,6 +71,7 @@ import com.wire.android.ui.common.snackbar.LocalSnackbarHostState
import com.wire.android.ui.common.topappbar.CommonTopAppBar
import com.wire.android.ui.common.topappbar.CommonTopAppBarViewModel
import com.wire.android.ui.destinations.ConversationScreenDestination
import com.wire.android.ui.destinations.E2eiCertificateDetailsScreenDestination
import com.wire.android.ui.destinations.HomeScreenDestination
import com.wire.android.ui.destinations.ImportMediaScreenDestination
import com.wire.android.ui.destinations.IncomingCallScreenDestination
Expand All @@ -81,6 +83,7 @@ import com.wire.android.ui.destinations.SelfDevicesScreenDestination
import com.wire.android.ui.destinations.SelfUserProfileScreenDestination
import com.wire.android.ui.destinations.WelcomeScreenDestination
import com.wire.android.ui.home.E2EIRequiredDialog
import com.wire.android.ui.home.E2EIResultDialog
import com.wire.android.ui.home.E2EISnoozeDialog
import com.wire.android.ui.home.appLock.LockCodeTimeManager
import com.wire.android.ui.home.sync.FeatureFlagNotificationViewModel
Expand Down Expand Up @@ -269,6 +272,7 @@ class WireActivity : AppCompatActivity() {
LaunchedEffect(userId) {
featureFlagNotificationViewModel.loadInitialSync()
}
val context = LocalContext.current
with(featureFlagNotificationViewModel.featureFlagState) {
if (shouldShowTeamAppLockDialog) {
TeamAppLockFeatureFlagDialog(
Expand Down Expand Up @@ -330,8 +334,9 @@ class WireActivity : AppCompatActivity() {

e2EIRequired?.let {
E2EIRequiredDialog(
result = e2EIRequired,
getCertificate = featureFlagNotificationViewModel::getE2EICertificate,
e2EIRequired = e2EIRequired,
isE2EILoading = isE2EILoading,
getCertificate = { featureFlagNotificationViewModel.getE2EICertificate(it, context) },
snoozeDialog = featureFlagNotificationViewModel::snoozeE2EIdRequiredDialog
)
}
Expand All @@ -343,6 +348,17 @@ class WireActivity : AppCompatActivity() {
)
}

e2EIResult?.let {
E2EIResultDialog(
result = e2EIResult,
updateCertificate = { featureFlagNotificationViewModel.getE2EICertificate(it, context) },
snoozeDialog = featureFlagNotificationViewModel::snoozeE2EIdRequiredDialog,
openCertificateDetails = { navigate(NavigationCommand(E2eiCertificateDetailsScreenDestination(it))) },
dismissSuccessDialog = featureFlagNotificationViewModel::dismissSuccessE2EIdDialog,
isE2EILoading = isE2EILoading
)
}

UpdateAppDialog(viewModel.globalAppState.updateAppDialog, ::updateTheApp)
JoinConversationDialog(
viewModel.globalAppState.conversationJoinedDialog,
Expand Down
125 changes: 101 additions & 24 deletions app/src/main/kotlin/com/wire/android/ui/home/E2EIDialogs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,77 @@ import kotlin.time.Duration.Companion.seconds

@Composable
fun E2EIRequiredDialog(
result: FeatureFlagState.E2EIRequired,
getCertificate: () -> Unit,
e2EIRequired: FeatureFlagState.E2EIRequired,
isE2EILoading: Boolean,
getCertificate: (FeatureFlagState.E2EIRequired) -> Unit,
snoozeDialog: (FeatureFlagState.E2EIRequired.WithGracePeriod) -> Unit,
) {
when (result) {
FeatureFlagState.E2EIRequired.NoGracePeriod.Create -> E2EIRequiredNoSnoozeDialog(getCertificate = getCertificate)
FeatureFlagState.E2EIRequired.NoGracePeriod.Renew -> E2EIRenewNoSnoozeDialog(updateCertificate = getCertificate)
when (e2EIRequired) {
FeatureFlagState.E2EIRequired.NoGracePeriod.Create -> E2EIRequiredNoSnoozeDialog(
isLoading = isE2EILoading,
getCertificate = { getCertificate(e2EIRequired) }
)

FeatureFlagState.E2EIRequired.NoGracePeriod.Renew -> E2EIRenewNoSnoozeDialog(
isLoading = isE2EILoading,
updateCertificate = { getCertificate(e2EIRequired) }
)

is FeatureFlagState.E2EIRequired.WithGracePeriod.Create -> E2EIRequiredWithSnoozeDialog(
getCertificate = getCertificate,
snoozeDialog = { snoozeDialog(result) }
isLoading = isE2EILoading,
getCertificate = { getCertificate(e2EIRequired) },
snoozeDialog = { snoozeDialog(e2EIRequired) }
)

is FeatureFlagState.E2EIRequired.WithGracePeriod.Renew -> E2EIRenewWithSnoozeDialog(
updateCertificate = getCertificate,
snoozeDialog = { snoozeDialog(result) }
isLoading = isE2EILoading,
updateCertificate = { getCertificate(e2EIRequired) },
snoozeDialog = { snoozeDialog(e2EIRequired) }
)
}
}

@Composable
fun E2EIResultDialog(
result: FeatureFlagState.E2EIResult,
isE2EILoading: Boolean,
updateCertificate: (FeatureFlagState.E2EIRequired) -> Unit,
snoozeDialog: (FeatureFlagState.E2EIRequired.WithGracePeriod) -> Unit,
openCertificateDetails: (String) -> Unit,
dismissSuccessDialog: () -> Unit
) {
when (result) {
is FeatureFlagState.E2EIResult.Failure -> E2EIRenewErrorDialog(
e2EIRequired = result.e2EIRequired,
isE2EILoading = isE2EILoading,
updateCertificate = { updateCertificate(result.e2EIRequired) },
snoozeDialog = snoozeDialog
)

is FeatureFlagState.E2EIResult.Success -> E2EISuccessDialog(
openCertificateDetails = { openCertificateDetails(result.certificate) },
dismissDialog = dismissSuccessDialog
)
}
}

@Composable
fun E2EIRenewErrorDialog(
result: FeatureFlagState.E2EIRequired,
e2EIRequired: FeatureFlagState.E2EIRequired,
isE2EILoading: Boolean,
updateCertificate: () -> Unit,
snoozeDialog: (FeatureFlagState.E2EIRequired.WithGracePeriod) -> Unit,
) {
when (result) {
is FeatureFlagState.E2EIRequired.NoGracePeriod -> E2EIErrorNoSnoozeDialog(updateCertificate = updateCertificate)
when (e2EIRequired) {
is FeatureFlagState.E2EIRequired.NoGracePeriod -> E2EIErrorNoSnoozeDialog(
isE2EILoading = isE2EILoading,
updateCertificate = updateCertificate
)

is FeatureFlagState.E2EIRequired.WithGracePeriod -> E2EIErrorWithSnoozeDialog(
updateCertificate = updateCertificate,
snoozeDialog = { snoozeDialog(result) }
isE2EILoading = isE2EILoading,
snoozeDialog = { snoozeDialog(e2EIRequired) }
)
}
}
Expand Down Expand Up @@ -151,19 +192,47 @@ fun E2EISuccessDialog(
)
}

@Composable
fun E2EIErrorWithDismissDialog(
isE2EILoading: Boolean,
updateCertificate: () -> Unit,
onDismiss: () -> Unit
) {
WireDialog(
title = stringResource(id = R.string.end_to_end_identity_renew_error_dialog_title),
text = stringResource(id = R.string.end_to_end_identity_renew_error_dialog_text),
onDismiss = onDismiss,
optionButton1Properties = WireDialogButtonProperties(
onClick = updateCertificate,
text = stringResource(id = R.string.label_retry),
type = WireDialogButtonType.Primary,
loading = isE2EILoading
),
optionButton2Properties = WireDialogButtonProperties(
onClick = onDismiss,
text = stringResource(id = R.string.label_cancel),
type = WireDialogButtonType.Secondary,
),
buttonsHorizontalAlignment = false,
properties = DialogProperties(usePlatformDefaultWidth = false)
)
}

@Composable
private fun E2EIErrorWithSnoozeDialog(
isE2EILoading: Boolean,
updateCertificate: () -> Unit,
snoozeDialog: () -> Unit
) {
WireDialog(
title = stringResource(id = R.string.end_to_end_identity_renew_error_dialog_title),
text = stringResource(id = R.string.end_to_end_identity_renew_error_dialog_text),
onDismiss = updateCertificate,
onDismiss = snoozeDialog,
optionButton1Properties = WireDialogButtonProperties(
onClick = updateCertificate,
text = stringResource(id = R.string.label_retry),
type = WireDialogButtonType.Primary,
loading = isE2EILoading
),
optionButton2Properties = WireDialogButtonProperties(
onClick = snoozeDialog,
Expand All @@ -177,6 +246,7 @@ private fun E2EIErrorWithSnoozeDialog(

@Composable
private fun E2EIErrorNoSnoozeDialog(
isE2EILoading: Boolean,
updateCertificate: () -> Unit
) {
WireDialog(
Expand All @@ -187,6 +257,7 @@ private fun E2EIErrorNoSnoozeDialog(
onClick = updateCertificate,
text = stringResource(id = R.string.label_retry),
type = WireDialogButtonType.Primary,
loading = isE2EILoading
),
properties = DialogProperties(
usePlatformDefaultWidth = false,
Expand All @@ -198,6 +269,7 @@ private fun E2EIErrorNoSnoozeDialog(

@Composable
private fun E2EIRequiredWithSnoozeDialog(
isLoading: Boolean,
getCertificate: () -> Unit,
snoozeDialog: () -> Unit
) {
Expand All @@ -209,6 +281,7 @@ private fun E2EIRequiredWithSnoozeDialog(
onClick = getCertificate,
text = stringResource(id = R.string.end_to_end_identity_required_dialog_positive_button),
type = WireDialogButtonType.Primary,
loading = isLoading
),
optionButton2Properties = WireDialogButtonProperties(
onClick = snoozeDialog,
Expand All @@ -221,7 +294,7 @@ private fun E2EIRequiredWithSnoozeDialog(
}

@Composable
private fun E2EIRequiredNoSnoozeDialog(getCertificate: () -> Unit) {
private fun E2EIRequiredNoSnoozeDialog(isLoading: Boolean, getCertificate: () -> Unit) {
WireDialog(
title = stringResource(id = R.string.end_to_end_identity_required_dialog_title),
text = stringResource(id = R.string.end_to_end_identity_required_dialog_text_no_snooze),
Expand All @@ -230,6 +303,7 @@ private fun E2EIRequiredNoSnoozeDialog(getCertificate: () -> Unit) {
onClick = getCertificate,
text = stringResource(id = R.string.end_to_end_identity_required_dialog_positive_button),
type = WireDialogButtonType.Primary,
loading = isLoading
),
buttonsHorizontalAlignment = false,
properties = DialogProperties(
Expand All @@ -242,6 +316,7 @@ private fun E2EIRequiredNoSnoozeDialog(getCertificate: () -> Unit) {

@Composable
private fun E2EIRenewWithSnoozeDialog(
isLoading: Boolean,
updateCertificate: () -> Unit,
snoozeDialog: () -> Unit
) {
Expand All @@ -253,6 +328,7 @@ private fun E2EIRenewWithSnoozeDialog(
onClick = updateCertificate,
text = stringResource(id = R.string.end_to_end_identity_renew_dialog_positive_button),
type = WireDialogButtonType.Primary,
loading = isLoading
),
optionButton2Properties = WireDialogButtonProperties(
onClick = snoozeDialog,
Expand All @@ -265,7 +341,7 @@ private fun E2EIRenewWithSnoozeDialog(
}

@Composable
private fun E2EIRenewNoSnoozeDialog(updateCertificate: () -> Unit) {
private fun E2EIRenewNoSnoozeDialog(isLoading: Boolean, updateCertificate: () -> Unit) {
WireDialog(
title = stringResource(id = R.string.end_to_end_identity_renew_dialog_title),
text = stringResource(id = R.string.end_to_end_identity_renew_dialog_text_no_snooze),
Expand All @@ -274,6 +350,7 @@ private fun E2EIRenewNoSnoozeDialog(updateCertificate: () -> Unit) {
onClick = updateCertificate,
text = stringResource(id = R.string.end_to_end_identity_renew_dialog_positive_button),
type = WireDialogButtonType.Primary,
loading = isLoading
),
buttonsHorizontalAlignment = false,
properties = DialogProperties(
Expand All @@ -288,31 +365,31 @@ private fun E2EIRenewNoSnoozeDialog(updateCertificate: () -> Unit) {
@Composable
fun previewE2EIdRequiredWithSnoozeDialog() {
WireTheme {
E2EIRequiredWithSnoozeDialog({}) {}
E2EIRequiredWithSnoozeDialog(false, {}) {}
}
}

@PreviewMultipleThemes
@Composable
fun previewE2EIdRequiredNoSnoozeDialog() {
WireTheme {
E2EIRequiredNoSnoozeDialog {}
E2EIRequiredNoSnoozeDialog(false) {}
}
}

@PreviewMultipleThemes
@Composable
fun previewE2EIdRenewRequiredWithSnoozeDialog() {
WireTheme {
E2EIRenewWithSnoozeDialog({}) {}
E2EIRenewWithSnoozeDialog(false, {}) {}
}
}

@PreviewMultipleThemes
@Composable
fun previewE2EIdRenewRequiredNoSnoozeDialog() {
WireTheme {
E2EIRenewNoSnoozeDialog {}
E2EIRenewNoSnoozeDialog(false) {}
}
}

Expand All @@ -328,15 +405,15 @@ fun previewE2EIdSnoozeDialog() {
@Composable
fun previewE2EIRenewErrorDialogNoGracePeriod() {
WireTheme {
E2EIRenewErrorDialog(FeatureFlagState.E2EIRequired.NoGracePeriod.Renew, { }) {}
E2EIRenewErrorDialog(FeatureFlagState.E2EIRequired.NoGracePeriod.Renew, false, { }) {}
}
}

@PreviewMultipleThemes
@Composable
fun previewE2EIRenewErrorDialogWithGracePeriod() {
WireTheme {
E2EIRenewErrorDialog(FeatureFlagState.E2EIRequired.WithGracePeriod.Renew(2.days), { }) {}
E2EIRenewErrorDialog(FeatureFlagState.E2EIRequired.WithGracePeriod.Renew(2.days), false, { }) {}
}
}

Expand All @@ -352,14 +429,14 @@ fun previewE2EISuccessDialog() {
@Composable
fun previewE2EIRenewErrorNoSnoozeDialog() {
WireTheme {
E2EIErrorNoSnoozeDialog { }
E2EIErrorNoSnoozeDialog(false) { }
}
}

@PreviewMultipleThemes
@Composable
fun previewE2EIRenewErrorWithSnoozeDialog() {
WireTheme {
E2EIErrorWithSnoozeDialog(updateCertificate = {}) { }
E2EIErrorWithSnoozeDialog(isE2EILoading = false, updateCertificate = {}) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ data class FeatureFlagState(
val areSelfDeletedMessagesEnabled: Boolean = true,
val e2EIRequired: E2EIRequired? = null,
val e2EISnoozeInfo: E2EISnooze? = null,
val e2EIResult: E2EIResult? = null,
val isE2EILoading: Boolean = false,
val showCallEndedBecauseOfConversationDegraded: Boolean = false
) {
enum class SharingRestrictedState {
Expand All @@ -56,4 +58,9 @@ data class FeatureFlagState(
data object Renew : NoGracePeriod()
}
}

sealed class E2EIResult {
data class Failure(val e2EIRequired: E2EIRequired) : E2EIResult()
data class Success(val certificate: String) : E2EIResult()
}
}
Loading

0 comments on commit 961efb4

Please sign in to comment.