Skip to content

Commit

Permalink
Fix strings and improve state step logic in SharedSecureStorageViewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
amitkma committed Dec 7, 2022
1 parent 2f30718 commit d2966fc
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 42 deletions.
6 changes: 4 additions & 2 deletions library/ui-strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@
<string name="action_disconnect">Disconnect</string>
<string name="action_play">Play</string>
<string name="action_dismiss">Dismiss</string>
<string name="action_reset">Proceed to Reset</string>
<string name="action_reset">Reset</string>
<string name="action_proceed_to_reset">Proceed to reset</string>
<string name="action_learn_more">Learn more</string>
<string name="action_next">Next</string>
<string name="action_got_it">Got it</string>
Expand Down Expand Up @@ -2634,7 +2635,8 @@
<string name="failed_to_access_secure_storage">Failed to access secure storage</string>
<string name="bad_passphrase_key_reset_all_action">Forgot or lost all recovery options? Reset everything</string>
<string name="secure_backup_reset_all">Reset everything</string>
<string name="secure_backup_reset_all_no_other_devices">Resetting your verification keys cannot be undone. After resetting, you won't have access to old encrypted messages, and any friends who have previously verified you will see security warnings until you re-verify with them.</string>
<string name="secure_backup_reset_all_no_other_devices">Only do this if you have no other device you can verify this device with.</string>
<string name="secure_backup_reset_all_no_other_devices_long">Resetting your verification keys cannot be undone. After resetting, you won\'t have access to old encrypted messages, and any friends who have previously verified you will see security warnings until you re-verify with them.</string>
<string name="secure_backup_reset_if_you_reset_all">If you reset everything</string>
<string name="secure_backup_reset_no_history">You will restart with no history, no messages, trusted devices or trusted users</string>
<string name="secure_backup_reset_danger_warning">Please only proceed if you\'re sure you\'ve lost all of your other devices and your security key.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ package org.matrix.android.sdk.internal.session.room.summary

import io.realm.Realm
import io.realm.kotlin.createObject
import kotlinx.coroutines.runBlocking
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.content.EncryptionEventContent
import org.matrix.android.sdk.api.session.events.model.toModel
Expand All @@ -41,7 +39,6 @@ import org.matrix.android.sdk.api.session.room.send.SendState
import org.matrix.android.sdk.api.session.sync.model.RoomSyncSummary
import org.matrix.android.sdk.api.session.sync.model.RoomSyncUnreadNotifications
import org.matrix.android.sdk.api.session.sync.model.RoomSyncUnreadThreadNotifications
import org.matrix.android.sdk.internal.crypto.EventDecryptor
import org.matrix.android.sdk.internal.database.mapper.ContentMapper
import org.matrix.android.sdk.internal.database.mapper.asDomain
import org.matrix.android.sdk.internal.database.model.CurrentStateEventEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ internal class RoomSummaryEventDecryptor @Inject constructor(
}

private val scope: CoroutineScope = CoroutineScope(
cryptoCoroutineScope.coroutineContext
+ SupervisorJob()
+ CoroutineName("RoomSummaryDecryptor")
cryptoCoroutineScope.coroutineContext +
SupervisorJob() +
CoroutineName("RoomSummaryDecryptor")
)

private val channel = Channel<Message>(capacity = 300)
Expand Down Expand Up @@ -116,8 +116,8 @@ internal class RoomSummaryEventDecryptor @Inject constructor(
}
}

if (failure.errorType == MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID
|| failure.errorType == MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX) {
if (failure.errorType == MXCryptoError.ErrorType.UNKNOWN_INBOUND_SESSION_ID ||
failure.errorType == MXCryptoError.ErrorType.UNKNOWN_MESSAGE_INDEX) {
(event.content["session_id"] as? String)?.let { sessionId ->
unknownSessionsFailure.getOrPut(sessionId) { mutableSetOf() }
.add(event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package org.matrix.android.sdk.api.session.crypto.keysbackup

import org.matrix.android.sdk.api.session.securestorage.SsssPassphrase

object BackupUtils {
fun recoveryKeyFromBase58(key: String): IBackupRecoveryKey? = BackupRecoveryKey.fromBase58(key)
fun recoveryKeyFromPassphrase(passphrase: String): IBackupRecoveryKey? = BackupRecoveryKey.newFromPassphrase(passphrase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import org.matrix.android.sdk.api.session.crypto.crosssigning.DeviceTrustLevel
import org.matrix.android.sdk.api.session.crypto.crosssigning.MXCrossSigningInfo
import org.matrix.android.sdk.api.session.crypto.crosssigning.PrivateKeysInfo
import org.matrix.android.sdk.api.session.crypto.crosssigning.UserTrustResult
import org.matrix.android.sdk.api.session.crypto.keysbackup.MegolmBackupAuthData
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
import org.matrix.android.sdk.api.session.crypto.model.ImportRoomKeysResult
import org.matrix.android.sdk.api.session.crypto.model.MXEventDecryptionResult
Expand All @@ -52,7 +51,6 @@ import org.matrix.android.sdk.api.util.JsonDict
import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.api.util.toOptional
import org.matrix.android.sdk.internal.coroutines.builder.safeInvokeOnClose
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.CreateKeysBackupVersionBody
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.DefaultKeysAlgorithmAndData
import org.matrix.android.sdk.internal.crypto.keysbackup.model.rest.KeysAlgorithmAndData
import org.matrix.android.sdk.internal.crypto.network.RequestSender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,32 +114,35 @@ class SharedSecureStorageViewModel @AssistedInject constructor(
)
}
}
val keyResult = initialState.keyId?.let { session.sharedSecretStorageService().getKey(it) }
?: session.sharedSecretStorageService().getDefaultKey()

if (!keyResult.isSuccess()) {
_viewEvents.post(SharedSecureStorageViewEvent.Dismiss)
} else {
val info = (keyResult as KeyInfoResult.Success).keyInfo
if (info.content.passphrase != null) {
setState {
copy(
hasPassphrase = true,
ready = true,
step = if (initialState.step == SharedSecureStorageViewState.Step.ResetAll) SharedSecureStorageViewState.Step.ResetAll
else SharedSecureStorageViewState.Step.EnterPassphrase
)
}
if (initialState.step != SharedSecureStorageViewState.Step.ResetAll) {
val keyResult = initialState.keyId?.let { session.sharedSecretStorageService().getKey(it) }
?: session.sharedSecretStorageService().getDefaultKey()

if (!keyResult.isSuccess()) {
_viewEvents.post(SharedSecureStorageViewEvent.Dismiss)
} else {
setState {
copy(
hasPassphrase = false,
ready = true,
step = if (initialState.step == SharedSecureStorageViewState.Step.ResetAll) SharedSecureStorageViewState.Step.ResetAll
else SharedSecureStorageViewState.Step.EnterKey
)
val info = (keyResult as KeyInfoResult.Success).keyInfo
if (info.content.passphrase != null) {
setState {
copy(
hasPassphrase = true,
ready = true,
step = SharedSecureStorageViewState.Step.EnterPassphrase
)
}
} else {
setState {
copy(
hasPassphrase = false,
ready = true,
step = SharedSecureStorageViewState.Step.EnterKey
)
}
}
}
} else {
setState { copy(ready = true) }
}

session.flow()
Expand Down Expand Up @@ -215,7 +218,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor(
)
}
}
*/
*/
else -> {
_viewEvents.post(SharedSecureStorageViewEvent.Dismiss)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sealed class VerificationAction : VectorViewModelAction {
data class GotItConclusion(val verified: Boolean) : VerificationAction()
object FailedToGetKeysFrom4S : VerificationAction()
object SkipVerification : VerificationAction()
object ForgotResetAll: VerificationAction()
object ForgotResetAll : VerificationAction()
object VerifyFromPassphrase : VerificationAction()
object ReadyPendingVerification : VerificationAction()
object CancelPendingVerification : VerificationAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import im.vector.app.core.platform.VectorViewEvents
sealed class VerificationBottomSheetViewEvents : VectorViewEvents {
object Dismiss : VerificationBottomSheetViewEvents()
object AccessSecretStore : VerificationBottomSheetViewEvents()
object ResetAll: VerificationBottomSheetViewEvents()
object ResetAll : VerificationBottomSheetViewEvents()
object GoToSettings : VerificationBottomSheetViewEvents()
data class ModalError(val errorMessage: CharSequence) : VerificationBottomSheetViewEvents()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package im.vector.app.features.crypto.verification.self

import android.util.Log
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.Loading
Expand Down
4 changes: 2 additions & 2 deletions vector/src/main/res/layout/fragment_ssss_reset_all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="@string/secure_backup_reset_all_no_other_devices"
android:text="@string/secure_backup_reset_all_no_other_devices_long"
android:textColor="?vctr_content_primary"
app:layout_constraintBottom_toTopOf="@id/ssss_reset_other_devices"
app:layout_constraintTop_toBottomOf="@id/reset_title" />
Expand Down Expand Up @@ -87,7 +87,7 @@
style="@style/Widget.Vector.Button.Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/action_reset"
android:text="@string/action_proceed_to_reset"
tools:ignore="MissingConstraints" />

<androidx.constraintlayout.helper.widget.Flow
Expand Down

0 comments on commit d2966fc

Please sign in to comment.