Update the SDK, minor version, handle API breaks (#1994)

This commit is contained in:
Doug
2023-10-31 14:56:23 +00:00
committed by GitHub
parent b2f30974e3
commit 4af881a20f
9 changed files with 63 additions and 20 deletions
@@ -2697,17 +2697,22 @@ class SecureBackupControllerMock: SecureBackupControllerProtocol {
return isLastSessionReturnValue
}
}
//MARK: - waitForKeyBackup
//MARK: - waitForKeyBackupUpload
var waitForKeyBackupCallsCount = 0
var waitForKeyBackupCalled: Bool {
return waitForKeyBackupCallsCount > 0
var waitForKeyBackupUploadCallsCount = 0
var waitForKeyBackupUploadCalled: Bool {
return waitForKeyBackupUploadCallsCount > 0
}
var waitForKeyBackupClosure: (() async -> Void)?
var waitForKeyBackupUploadReturnValue: Result<Void, SecureBackupControllerError>!
var waitForKeyBackupUploadClosure: (() async -> Result<Void, SecureBackupControllerError>)?
func waitForKeyBackup() async {
waitForKeyBackupCallsCount += 1
await waitForKeyBackupClosure?()
func waitForKeyBackupUpload() async -> Result<Void, SecureBackupControllerError> {
waitForKeyBackupUploadCallsCount += 1
if let waitForKeyBackupUploadClosure = waitForKeyBackupUploadClosure {
return await waitForKeyBackupUploadClosure()
} else {
return waitForKeyBackupUploadReturnValue
}
}
}
class SessionVerificationControllerProxyMock: SessionVerificationControllerProxyProtocol {
@@ -30,6 +30,15 @@ enum SecureBackupLogoutConfirmationScreenViewMode {
struct SecureBackupLogoutConfirmationScreenViewState: BindableState {
var mode: SecureBackupLogoutConfirmationScreenViewMode
var bindings = SecureBackupLogoutConfirmationScreenBindings()
}
struct SecureBackupLogoutConfirmationScreenBindings {
var alertInfo: AlertInfo<SecureBackupLogoutConfirmationScreenAlertType>?
}
enum SecureBackupLogoutConfirmationScreenAlertType {
case backupUploadFailed
}
enum SecureBackupLogoutConfirmationScreenViewAction {
@@ -77,7 +77,18 @@ class SecureBackupLogoutConfirmationScreenViewModel: SecureBackupLogoutConfirmat
state.mode = networkMonitor.reachabilityPublisher.value == .reachable ? .backupOngoing : .offline
keyUploadWaitingTask = Task {
await secureBackupController.waitForKeyBackup()
var result = await secureBackupController.waitForKeyBackupUpload()
if case .failure = result {
// Retry the upload first, conditions might have changed.
result = await secureBackupController.waitForKeyBackupUpload()
}
guard case .success = result else {
MXLog.error("Aborting logout due to failure waiting for backup upload.")
state.bindings.alertInfo = .init(id: .backupUploadFailed)
return
}
guard !Task.isCancelled else { return }
@@ -33,6 +33,7 @@ struct SecureBackupLogoutConfirmationScreen: View {
.toolbar { toolbar }
.background(Color.compound.bgCanvasDefault.ignoresSafeArea())
.safeAreaInset(edge: .bottom) { footer.padding() }
.alert(item: $context.alertInfo)
}
}
@@ -122,8 +122,23 @@ class SecureBackupController: SecureBackupControllerProtocol {
}
}
func waitForKeyBackup() async {
await encryption.waitForBackupUploadSteadyState(progressListener: nil)
func waitForKeyBackupUpload() async -> Result<Void, SecureBackupControllerError> {
do {
try await encryption.waitForBackupUploadSteadyState(progressListener: nil)
return .success(())
} catch let error as SteadyStateError {
switch error {
case .BackupDisabled:
MXLog.error("Key backup disabled, continuing logout.")
return .success(())
case .Connection, .Laged:
MXLog.error("Key backup upload failure: \(error)")
return .failure(.failedUploadingForBackup)
}
} catch {
MXLog.error("Unknown key backup upload failure")
return .failure(.failedUploadingForBackup)
}
}
}
@@ -45,6 +45,8 @@ enum SecureBackupControllerError: Error {
case failedConfirmingRecoveryKey
case failedFetchingSessionState
case failedUploadingForBackup
}
// sourcery: AutoMockable
@@ -61,7 +63,7 @@ protocol SecureBackupControllerProtocol {
func isLastSession() async -> Result<Bool, SecureBackupControllerError>
func waitForKeyBackup() async
func waitForKeyBackupUpload() async -> Result<Void, SecureBackupControllerError>
}
extension SecureBackupControllerMock {