mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
@@ -45,6 +45,8 @@ class ClientProxy: ClientProxyProtocol {
|
||||
|
||||
let notificationSettings: NotificationSettingsProxyProtocol
|
||||
|
||||
let secureBackupController: SecureBackupControllerProtocol
|
||||
|
||||
private let roomListRecencyOrderingAllowedEventTypes = ["m.room.message", "m.room.encrypted", "m.sticker"]
|
||||
|
||||
private var loadCachedAvatarURLTask: Task<Void, Never>?
|
||||
@@ -93,6 +95,8 @@ class ClientProxy: ClientProxyProtocol {
|
||||
|
||||
notificationSettings = NotificationSettingsProxy(notificationSettings: client.getNotificationSettings(),
|
||||
backgroundTaskService: backgroundTaskService)
|
||||
|
||||
secureBackupController = SecureBackupController()
|
||||
|
||||
client.setDelegate(delegate: ClientDelegateWrapper { [weak self] isSoftLogout in
|
||||
self?.hasEncounteredAuthError = true
|
||||
|
||||
@@ -95,6 +95,8 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
|
||||
|
||||
var notificationSettings: NotificationSettingsProxyProtocol { get }
|
||||
|
||||
var secureBackupController: SecureBackupControllerProtocol { get }
|
||||
|
||||
func startSync()
|
||||
|
||||
func stopSync()
|
||||
|
||||
@@ -39,6 +39,13 @@ class MockClientProxy: ClientProxyProtocol {
|
||||
var userDisplayName: CurrentValuePublisher<String?, Never> { CurrentValueSubject<String?, Never>("User display name").asCurrentValuePublisher() }
|
||||
|
||||
var notificationSettings: NotificationSettingsProxyProtocol = NotificationSettingsProxyMock(with: .init())
|
||||
|
||||
lazy var secureBackupController: SecureBackupControllerProtocol = {
|
||||
let secureBackupController = SecureBackupControllerMock()
|
||||
secureBackupController.underlyingRecoveryKeyState = .init(CurrentValueSubject<SecureBackupRecoveryKeyState, Never>(.disabled))
|
||||
secureBackupController.underlyingKeyBackupState = .init(CurrentValueSubject<SecureBackupKeyBackupState, Never>(.enabled))
|
||||
return secureBackupController
|
||||
}()
|
||||
|
||||
init(userID: String, deviceID: String? = nil, roomSummaryProvider: RoomSummaryProviderProtocol? = MockRoomSummaryProvider()) {
|
||||
self.userID = userID
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
class SecureBackupController: SecureBackupControllerProtocol {
|
||||
private let recoveryKeyStateSubject = CurrentValueSubject<SecureBackupRecoveryKeyState, Never>(.disabled)
|
||||
private let keyBackupStateSubject = CurrentValueSubject<SecureBackupKeyBackupState, Never>(.enabled)
|
||||
|
||||
var recoveryKeyState: CurrentValuePublisher<SecureBackupRecoveryKeyState, Never> {
|
||||
recoveryKeyStateSubject.asCurrentValuePublisher()
|
||||
}
|
||||
|
||||
var keyBackupState: CurrentValuePublisher<SecureBackupKeyBackupState, Never> {
|
||||
keyBackupStateSubject.asCurrentValuePublisher()
|
||||
}
|
||||
|
||||
func enableBackup() async -> Result<Void, SecureBackupControllerError> {
|
||||
keyBackupStateSubject.send(.enabling)
|
||||
|
||||
try? await Task.sleep(for: .seconds(1))
|
||||
|
||||
keyBackupStateSubject.send(.enabled)
|
||||
|
||||
return .success(())
|
||||
}
|
||||
|
||||
func disableBackup() async -> Result<Void, SecureBackupControllerError> {
|
||||
keyBackupStateSubject.send(.disabling)
|
||||
|
||||
try? await Task.sleep(for: .seconds(1))
|
||||
|
||||
keyBackupStateSubject.send(.disabled)
|
||||
|
||||
return .success(())
|
||||
}
|
||||
|
||||
static var wohoo = 0
|
||||
|
||||
func generateRecoveryKey() async -> Result<String, SecureBackupControllerError> {
|
||||
recoveryKeyStateSubject.send(.settingUp)
|
||||
|
||||
try? await Task.sleep(for: .seconds(1))
|
||||
|
||||
if Self.wohoo > 0, Self.wohoo % 2 == 1 {
|
||||
recoveryKeyStateSubject.send(.incomplete)
|
||||
} else {
|
||||
recoveryKeyStateSubject.send(.enabled)
|
||||
}
|
||||
|
||||
Self.wohoo += 1
|
||||
|
||||
return .success(UUID().uuidString)
|
||||
}
|
||||
|
||||
func confirmRecoveryKey(_ key: String) async -> Result<Void, SecureBackupControllerError> {
|
||||
recoveryKeyStateSubject.send(.settingUp)
|
||||
|
||||
try? await Task.sleep(for: .seconds(1))
|
||||
|
||||
recoveryKeyStateSubject.send(.enabled)
|
||||
|
||||
return .success(())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
enum SecureBackupRecoveryKeyState {
|
||||
case unknown
|
||||
case disabled
|
||||
case enabled
|
||||
/// Recovery is not set up properly, the user will need to re-enter it so we can cleanup
|
||||
/// https://github.com/vector-im/element-meta/issues/2107
|
||||
case incomplete
|
||||
case settingUp
|
||||
}
|
||||
|
||||
enum SecureBackupKeyBackupState {
|
||||
case unknown
|
||||
case enabling
|
||||
case enabled
|
||||
case disabling
|
||||
case disabled
|
||||
}
|
||||
|
||||
enum SecureBackupControllerError: Error {
|
||||
case failedEnablingKeyBackup
|
||||
case failedDisablingKeyBackup
|
||||
|
||||
case failedGeneratingRecoveryKey
|
||||
case failedConfirmingRecoveryKey
|
||||
}
|
||||
|
||||
// sourcery: AutoMockable
|
||||
protocol SecureBackupControllerProtocol {
|
||||
var recoveryKeyState: CurrentValuePublisher<SecureBackupRecoveryKeyState, Never> { get }
|
||||
|
||||
var keyBackupState: CurrentValuePublisher<SecureBackupKeyBackupState, Never> { get }
|
||||
|
||||
func enableBackup() async -> Result<Void, SecureBackupControllerError>
|
||||
func disableBackup() async -> Result<Void, SecureBackupControllerError>
|
||||
|
||||
func generateRecoveryKey() async -> Result<String, SecureBackupControllerError>
|
||||
func confirmRecoveryKey(_ key: String) async -> Result<Void, SecureBackupControllerError>
|
||||
}
|
||||
|
||||
extension SecureBackupControllerMock {
|
||||
convenience init(keyBackupState: SecureBackupKeyBackupState, recoveryKeyState: SecureBackupRecoveryKeyState) {
|
||||
self.init()
|
||||
underlyingKeyBackupState = CurrentValueSubject<SecureBackupKeyBackupState, Never>(keyBackupState).asCurrentValuePublisher()
|
||||
underlyingRecoveryKeyState = CurrentValueSubject<SecureBackupRecoveryKeyState, Never>(recoveryKeyState).asCurrentValuePublisher()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user