mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Add a service and flow coordinator for the LinkNewDevice feature. (#4859)
* Add a LinkNewDeviceService that exposes the SDK's grant QR code login methods. * Add a flow coordinator for linking a new device. Changes the presentation too.
This commit is contained in:
@@ -4019,6 +4019,70 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
|
||||
return removeUserAvatarReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - linkNewDeviceService
|
||||
|
||||
var linkNewDeviceServiceUnderlyingCallsCount = 0
|
||||
var linkNewDeviceServiceCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return linkNewDeviceServiceUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = linkNewDeviceServiceUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
linkNewDeviceServiceUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
linkNewDeviceServiceUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var linkNewDeviceServiceCalled: Bool {
|
||||
return linkNewDeviceServiceCallsCount > 0
|
||||
}
|
||||
|
||||
var linkNewDeviceServiceUnderlyingReturnValue: LinkNewDeviceService!
|
||||
var linkNewDeviceServiceReturnValue: LinkNewDeviceService! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return linkNewDeviceServiceUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: LinkNewDeviceService? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = linkNewDeviceServiceUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
linkNewDeviceServiceUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
linkNewDeviceServiceUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var linkNewDeviceServiceClosure: (() -> LinkNewDeviceService)?
|
||||
|
||||
func linkNewDeviceService() -> LinkNewDeviceService {
|
||||
linkNewDeviceServiceCallsCount += 1
|
||||
if let linkNewDeviceServiceClosure = linkNewDeviceServiceClosure {
|
||||
return linkNewDeviceServiceClosure()
|
||||
} else {
|
||||
return linkNewDeviceServiceReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - deactivateAccount
|
||||
|
||||
var deactivateAccountPasswordEraseDataUnderlyingCallsCount = 0
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// Copyright 2025 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
extension GrantLoginWithQrCodeHandlerSDKMock {
|
||||
struct Configuration {
|
||||
var generateDelay: Duration = .seconds(0)
|
||||
var generatedBase64QRCode = """
|
||||
TUFUUklYAgS0yzZ1QVpQ1jlnoxWX3d5jrWRFfELxjS2gN7pz9y+3PABaaHR0
|
||||
cHM6Ly9zeW5hcHNlLW9pZGMubGFiLmVsZW1lbnQuZGV2L19zeW5hcHNlL2Ns
|
||||
aWVudC9yZW5kZXp2b3VzLzAxSFg5SzAwUTFINktQRDQ3RUc0RzFUM1hHACVo
|
||||
dHRwczovL3N5bmFwc2Utb2lkYy5sYWIuZWxlbWVudC5kZXYv
|
||||
"""
|
||||
}
|
||||
|
||||
convenience init(_ configuration: Configuration) {
|
||||
self.init()
|
||||
|
||||
generateProgressListenerClosure = { listener in
|
||||
Task {
|
||||
try await Task.sleep(for: configuration.generateDelay)
|
||||
let bytes = Data(base64Encoded: configuration.generatedBase64QRCode) ?? Data()
|
||||
try listener.onUpdate(state: .qrReady(qrCode: .fromBytes(bytes: bytes)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user