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: Use enroll mls use case (WPB-5756) #2514

Merged
merged 11 commits into from
Dec 13, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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 @@
scope.launch {
when (oAuthResult) {
is OAuthUseCase.OAuthResult.Success -> {
enrollE2EI.finalizeEnrollment(
enrollmentResultHandler(enrollE2EI.finalizeEnrollment(

Check warning on line 64 in app/src/main/kotlin/com/wire/android/feature/e2ei/GetE2EICertificateUseCase.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/feature/e2ei/GetE2EICertificateUseCase.kt#L64

Added line #L64 was not covered by tests
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.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.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.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 @@
LaunchedEffect(userId) {
featureFlagNotificationViewModel.loadInitialSync()
}
val context = LocalContext.current

Check warning on line 275 in app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt#L275

Added line #L275 was not covered by tests
with(featureFlagNotificationViewModel.featureFlagState) {
if (shouldShowTeamAppLockDialog) {
TeamAppLockFeatureFlagDialog(
Expand Down Expand Up @@ -330,8 +334,9 @@

e2EIRequired?.let {
E2EIRequiredDialog(
result = e2EIRequired,
getCertificate = featureFlagNotificationViewModel::getE2EICertificate,
e2EIRequired = e2EIRequired,
isE2EILoading = isE2EILoading,
getCertificate = { featureFlagNotificationViewModel.getE2EICertificate(it, context) },

Check warning on line 339 in app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt#L337-L339

Added lines #L337 - L339 were not covered by tests
snoozeDialog = featureFlagNotificationViewModel::snoozeE2EIdRequiredDialog
)
}
Expand All @@ -343,6 +348,17 @@
)
}

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

Check warning on line 358 in app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt#L352-L358

Added lines #L352 - L358 were not covered by tests
)
}

Check warning on line 360 in app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt#L360

Added line #L360 was not covered by tests

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 @@
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 object Renew : NoGracePeriod()
}
}

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

Check warning on line 64 in app/src/main/kotlin/com/wire/android/ui/home/FeatureFlagState.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/home/FeatureFlagState.kt#L63-L64

Added lines #L63 - L64 were not covered by tests
}
}
Loading
Loading