Refactor cross signing banner.

This commit is contained in:
SBiOSoftWhare
2020-06-30 21:46:10 +02:00
parent aaca353748
commit ece9e77cd8
12 changed files with 176 additions and 141 deletions

View File

@@ -16,17 +16,15 @@
import Foundation
@objcMembers
final class KeyVerificationService: NSObject {
final class KeyVerificationService {
private let cameraAccessManager: CameraAccessManager
private var authenticatedSessionFactory: AuthenticatedSessionViewControllerFactory?
private var supportSetupKeyVerificationByUser: [String: Bool] = [:] // Cached server response
override init() {
init() {
self.cameraAccessManager = CameraAccessManager()
super.init()
}
func supportedKeyVerificationMethods() -> [String] {
@@ -42,43 +40,4 @@ final class KeyVerificationService: NSObject {
return supportedMethods
}
@discardableResult
func canSetupKeyVerification(for session: MXSession, success: @escaping ((Bool) -> Void), failure: @escaping ((Error) -> Void)) -> MXHTTPOperation? {
guard let crossSigning = session.crypto?.crossSigning, crossSigning.state == .notBootstrapped else {
// Cross-signing already setup
success(false)
return nil
}
let userId: String = session.myUserId
if let supportSetupKeyVerification = self.supportSetupKeyVerificationByUser[userId] {
// Return cached response
success(supportSetupKeyVerification)
return nil
}
let authenticatedSessionFactory = AuthenticatedSessionViewControllerFactory(session: session)
self.authenticatedSessionFactory = authenticatedSessionFactory
let path = "\(kMXAPIPrefixPathUnstable)/keys/device_signing/upload"
return authenticatedSessionFactory.hasSupport(forPath: path, httpMethod: "POST", success: { [weak self] succeeded in
guard let self = self else {
return
}
self.authenticatedSessionFactory = nil
self.supportSetupKeyVerificationByUser[userId] = succeeded
success(succeeded)
}, failure: { [weak self] error in
guard let self = self else {
return
}
self.authenticatedSessionFactory = nil
failure(error)
})
}
}