From efc1f38f8ce0e399f6fdce2fd4ef132f64996a00 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 12 Dec 2019 17:39:21 +0100 Subject: [PATCH] SoftLogout: adapt wording depending if all keys are backed up or not --- .../java/im/vector/riotx/core/extensions/Session.kt | 9 +++++++++ .../riotx/features/signout/SoftLogoutFragment.kt | 13 +++++++++++-- .../riotx/features/signout/SoftLogoutViewModel.kt | 4 +++- .../riotx/features/signout/SoftLogoutViewState.kt | 3 ++- .../features/workers/signout/SignOutUiWorker.kt | 4 +++- .../features/workers/signout/SignOutViewModel.kt | 10 ---------- vector/src/main/res/layout/fragment_soft_logout.xml | 11 +++++++++++ vector/src/main/res/values/strings_riotX.xml | 2 ++ 8 files changed, 41 insertions(+), 15 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/core/extensions/Session.kt b/vector/src/main/java/im/vector/riotx/core/extensions/Session.kt index 0ce4d04497..67e866bb82 100644 --- a/vector/src/main/java/im/vector/riotx/core/extensions/Session.kt +++ b/vector/src/main/java/im/vector/riotx/core/extensions/Session.kt @@ -19,6 +19,7 @@ package im.vector.riotx.core.extensions import androidx.lifecycle.Lifecycle import androidx.lifecycle.ProcessLifecycleOwner import im.vector.matrix.android.api.session.Session +import im.vector.matrix.android.api.session.crypto.keysbackup.KeysBackupState import im.vector.matrix.android.api.session.sync.FilterService import im.vector.riotx.features.notifications.PushRuleTriggerListener import im.vector.riotx.features.session.SessionListener @@ -40,3 +41,11 @@ fun Session.configureAndStart(pushRuleTriggerListener: PushRuleTriggerListener, // @Inject lateinit var incomingVerificationRequestHandler: IncomingVerificationRequestHandler // @Inject lateinit var keyRequestHandler: KeyRequestHandler } + +/** + * Tell is the session has unsaved e2e keys in the backup + */ +fun Session.hasUnsavedKeys(): Boolean { + return inboundGroupSessionsCount(false) > 0 + && getKeysBackupService().state != KeysBackupState.ReadyToBackUp +} diff --git a/vector/src/main/java/im/vector/riotx/features/signout/SoftLogoutFragment.kt b/vector/src/main/java/im/vector/riotx/features/signout/SoftLogoutFragment.kt index 99082527ed..1380b9cc5f 100644 --- a/vector/src/main/java/im/vector/riotx/features/signout/SoftLogoutFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/signout/SoftLogoutFragment.kt @@ -22,6 +22,7 @@ import android.os.Bundle import android.view.View import androidx.appcompat.app.AlertDialog import androidx.autofill.HintConstants +import androidx.core.view.isVisible import butterknife.OnClick import com.airbnb.mvrx.* import com.jakewharton.rxbinding3.widget.textChanges @@ -75,12 +76,18 @@ class SoftLogoutFragment @Inject constructor( } @OnClick(R.id.softLogoutClearDataSubmit) - fun clearData() { + fun clearData() = withState(softLogoutViewModel) { state -> cleanupUi() + val messageResId = if (state.hasUnsavedKeys) { + R.string.soft_logout_clear_data_dialog_content + } else { + R.string.soft_logout_clear_data_dialog_e2e_warning_content + } + AlertDialog.Builder(requireActivity()) .setTitle(R.string.soft_logout_clear_data_dialog_title) - .setMessage(R.string.soft_logout_clear_data_dialog_content) + .setMessage(messageResId) .setNegativeButton(R.string.cancel, null) .setPositiveButton(R.string.soft_logout_clear_data_submit) { _, _ -> MainActivity.restartApp(requireActivity(), MainActivityArgs( @@ -103,6 +110,8 @@ class SoftLogoutFragment @Inject constructor( state.homeServerUrl, state.userDisplayName, state.userId) + + softLogoutE2eWarningNotice.isVisible = state.hasUnsavedKeys } private fun setupSubmitButton() { diff --git a/vector/src/main/java/im/vector/riotx/features/signout/SoftLogoutViewModel.kt b/vector/src/main/java/im/vector/riotx/features/signout/SoftLogoutViewModel.kt index 8f6128093a..2ef69ceffb 100644 --- a/vector/src/main/java/im/vector/riotx/features/signout/SoftLogoutViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/signout/SoftLogoutViewModel.kt @@ -23,6 +23,7 @@ import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.util.Cancelable import im.vector.riotx.core.di.ActiveSessionHolder +import im.vector.riotx.core.extensions.hasUnsavedKeys import im.vector.riotx.core.extensions.toReducedUrl import im.vector.riotx.core.platform.VectorViewModel @@ -48,7 +49,8 @@ class SoftLogoutViewModel @AssistedInject constructor( return SoftLogoutViewState( homeServerUrl = activity.session.sessionParams.homeServerConnectionConfig.homeServerUri.toString().toReducedUrl(), userId = userId, - userDisplayName = activity.session.getUser(userId)?.displayName ?: userId + userDisplayName = activity.session.getUser(userId)?.displayName ?: userId, + hasUnsavedKeys = activity.session.hasUnsavedKeys() ) } diff --git a/vector/src/main/java/im/vector/riotx/features/signout/SoftLogoutViewState.kt b/vector/src/main/java/im/vector/riotx/features/signout/SoftLogoutViewState.kt index 24fb379df6..003a7af8e0 100644 --- a/vector/src/main/java/im/vector/riotx/features/signout/SoftLogoutViewState.kt +++ b/vector/src/main/java/im/vector/riotx/features/signout/SoftLogoutViewState.kt @@ -25,7 +25,8 @@ data class SoftLogoutViewState( val asyncLoginAction: Async = Uninitialized, val homeServerUrl: String, val userId: String, - val userDisplayName: String + val userDisplayName: String, + val hasUnsavedKeys: Boolean ) : MvRxState { fun isLoading(): Boolean { diff --git a/vector/src/main/java/im/vector/riotx/features/workers/signout/SignOutUiWorker.kt b/vector/src/main/java/im/vector/riotx/features/workers/signout/SignOutUiWorker.kt index 1fc3410870..abd15eb9e1 100644 --- a/vector/src/main/java/im/vector/riotx/features/workers/signout/SignOutUiWorker.kt +++ b/vector/src/main/java/im/vector/riotx/features/workers/signout/SignOutUiWorker.kt @@ -21,6 +21,7 @@ import androidx.appcompat.app.AlertDialog import androidx.fragment.app.FragmentActivity import im.vector.riotx.R import im.vector.riotx.core.di.ActiveSessionHolder +import im.vector.riotx.core.extensions.hasUnsavedKeys import im.vector.riotx.core.extensions.vectorComponent import im.vector.riotx.features.MainActivity import im.vector.riotx.features.MainActivityArgs @@ -32,7 +33,8 @@ class SignOutUiWorker(private val activity: FragmentActivity) { fun perform(context: Context) { activeSessionHolder = context.vectorComponent().activeSessionHolder() val session = activeSessionHolder.getActiveSession() - if (SignOutViewModel.doYouNeedToBeDisplayed(session)) { + if (session.hasUnsavedKeys()) { + // The backup check on logout flow has to be displayed if there are keys in the store, and the keys backup state is not Ready val signOutDialog = SignOutBottomSheetDialogFragment.newInstance() signOutDialog.onSignOut = Runnable { doSignOut() diff --git a/vector/src/main/java/im/vector/riotx/features/workers/signout/SignOutViewModel.kt b/vector/src/main/java/im/vector/riotx/features/workers/signout/SignOutViewModel.kt index 8964b29952..2526e8cbe3 100644 --- a/vector/src/main/java/im/vector/riotx/features/workers/signout/SignOutViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/workers/signout/SignOutViewModel.kt @@ -71,14 +71,4 @@ class SignOutViewModel @Inject constructor(private val session: Session) : ViewM session.getKeysBackupService().checkAndStartKeysBackup() } } - - companion object { - /** - * The backup check on logout flow has to be displayed if there are keys in the store, and the keys backup state is not Ready - */ - fun doYouNeedToBeDisplayed(session: Session): Boolean { - return session.inboundGroupSessionsCount(false) > 0 - && session.getKeysBackupService().state != KeysBackupState.ReadyToBackUp - } - } } diff --git a/vector/src/main/res/layout/fragment_soft_logout.xml b/vector/src/main/res/layout/fragment_soft_logout.xml index b534541ecc..0b4727831d 100644 --- a/vector/src/main/res/layout/fragment_soft_logout.xml +++ b/vector/src/main/res/layout/fragment_soft_logout.xml @@ -43,6 +43,17 @@ android:textAppearance="@style/TextAppearance.Vector.Login.Text" tools:text="@string/soft_logout_signin_notice" /> + + Sign in Your homeserver (%1$s) admin has signed you out of your account %2$s (%3$s). + Sign in to recover encryption keys stored exclusively on this device. You need them to read all of your secure messages on any device. Sign in Password Clear personal data @@ -156,6 +157,7 @@ Clear data Clear all data currently stored on this device?\nSign in again to access your account data and messages. + You’ll lose access to secure messages unless you sign in to recover your encryption keys. Clear data