Show recovery instead of verification if this is the last session and recovery is set up

* Show recovery instead of verification if this is the last session and recovery is set up

* Rename `recoveryKeyState` to `recoveryState`

* Remove duplicates on session security state changes.

* Fix missing "Save recovery key" button

* Fix unit tests

* Rename `isLastDevice` to `isOnlyDeviceLeft`

* Address PR comments
This commit is contained in:
Stefan Ceriu
2024-02-16 11:38:49 +02:00
committed by GitHub
parent e0c9f43026
commit db05540cc5
23 changed files with 255 additions and 208 deletions
@@ -166,6 +166,16 @@ class ClientProxy: ClientProxyProtocol {
let digest = SHA256.hash(data: data)
return digest.compactMap { String(format: "%02x", $0) }.joined()
}()
func isOnlyDeviceLeft() async -> Result<Bool, ClientProxyError> {
do {
let result = try await client.encryption().isLastDevice()
return .success(result)
} catch {
MXLog.error("Failed checking isLastDevice with error: \(error)")
return .failure(.failedCheckingIsLastDevice(error))
}
}
func startSync() {
guard !hasEncounteredAuthError else {
@@ -49,6 +49,7 @@ enum ClientProxyError: Error {
case failedSearchingUsers
case failedGettingUserProfile
case failedSettingUserAvatar
case failedCheckingIsLastDevice(Error?)
}
enum SlidingSyncConstants {
@@ -96,6 +97,8 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
var secureBackupController: SecureBackupControllerProtocol { get }
func isOnlyDeviceLeft() async -> Result<Bool, ClientProxyError>
func startSync()
func stopSync()
@@ -42,9 +42,8 @@ class MockClientProxy: ClientProxyProtocol {
lazy var secureBackupController: SecureBackupControllerProtocol = {
let secureBackupController = SecureBackupControllerMock()
secureBackupController.underlyingRecoveryKeyState = .init(CurrentValueSubject<SecureBackupRecoveryKeyState, Never>(.enabled))
secureBackupController.underlyingRecoveryState = .init(CurrentValueSubject<SecureBackupRecoveryState, Never>(.enabled))
secureBackupController.underlyingKeyBackupState = .init(CurrentValueSubject<SecureBackupKeyBackupState, Never>(.enabled))
secureBackupController.isLastSessionReturnValue = .success(false)
return secureBackupController
}()
@@ -54,6 +53,10 @@ class MockClientProxy: ClientProxyProtocol {
self.roomSummaryProvider = roomSummaryProvider
}
func isOnlyDeviceLeft() async -> Result<Bool, ClientProxyError> {
.success(false)
}
func startSync() { }
func stopSync() { }