From 755e4bf7a4503b637a13754e1abac739d76c0e44 Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Mon, 14 Jul 2025 14:31:06 +0100 Subject: [PATCH] Update the SDK and build a client before logging in with a QR code. (#4320) --- ElementX.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 4 +- .../AuthenticationClientBuilderMock.swift | 3 - .../Mocks/Generated/GeneratedMocks.swift | 74 ----------- .../Mocks/Generated/SDKGeneratedMocks.swift | 121 +++++++----------- .../AuthenticationClientBuilder.swift | 12 -- .../Services/QRCode/QRCodeLoginService.swift | 7 +- ...henticationStartScreenViewModelTests.swift | 3 +- ...rverConfirmationScreenViewModelTests.swift | 3 +- project.yml | 2 +- 10 files changed, 56 insertions(+), 175 deletions(-) diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 56b174508..6b2c8929a 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -8771,7 +8771,7 @@ repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift"; requirement = { kind = exactVersion; - version = 25.07.10; + version = "25.07.14-2"; }; }; 701C7BEF8F70F7A83E852DCC /* XCRemoteSwiftPackageReference "GZIP" */ = { diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 357da916b..0b49e0855 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -158,8 +158,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/element-hq/matrix-rust-components-swift", "state" : { - "revision" : "91d7262dfdea3eec2e6a6fff5ab303ca953dd90b", - "version" : "25.7.10" + "revision" : "08ec4eaad53ca384e41bcb72bc198f26d7b17bd5", + "version" : "25.7.14-2" } }, { diff --git a/ElementX/Sources/Mocks/AuthenticationClientBuilderMock.swift b/ElementX/Sources/Mocks/AuthenticationClientBuilderMock.swift index d98f3e359..4e7395e97 100644 --- a/ElementX/Sources/Mocks/AuthenticationClientBuilderMock.swift +++ b/ElementX/Sources/Mocks/AuthenticationClientBuilderMock.swift @@ -31,7 +31,6 @@ extension AuthenticationClientBuilderMock { supportsOIDCCreatePrompt: false, supportsPasswordLogin: false)) ] - var qrCodeClient = ClientSDKMock(configuration: .init()) } convenience init(configuration: Configuration) { @@ -43,7 +42,5 @@ extension AuthenticationClientBuilderMock { } return client } - - buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReturnValue = configuration.qrCodeClient } } diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index c5d75192a..a17e31a23 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -1972,80 +1972,6 @@ class AuthenticationClientBuilderMock: AuthenticationClientBuilderProtocol, @unc return buildHomeserverAddressReturnValue } } - //MARK: - buildWithQRCode - - var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerThrowableError: Error? - var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = 0 - var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerCallsCount: Int { - get { - if Thread.isMainThread { - return buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount - } else { - var returnValue: Int? = nil - DispatchQueue.main.sync { - returnValue = buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount - } - - return returnValue! - } - } - set { - if Thread.isMainThread { - buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = newValue - } else { - DispatchQueue.main.sync { - buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = newValue - } - } - } - } - var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerCalled: Bool { - return buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerCallsCount > 0 - } - var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReceivedArguments: (qrCodeData: QrCodeData, oidcConfiguration: OIDCConfigurationProxy, progressListener: SDKListener)? - var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReceivedInvocations: [(qrCodeData: QrCodeData, oidcConfiguration: OIDCConfigurationProxy, progressListener: SDKListener)] = [] - - var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue: ClientProtocol! - var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReturnValue: ClientProtocol! { - get { - if Thread.isMainThread { - return buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue - } else { - var returnValue: ClientProtocol? = nil - DispatchQueue.main.sync { - returnValue = buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue - } - - return returnValue! - } - } - set { - if Thread.isMainThread { - buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue = newValue - } else { - DispatchQueue.main.sync { - buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue = newValue - } - } - } - } - var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerClosure: ((QrCodeData, OIDCConfigurationProxy, SDKListener) async throws -> ClientProtocol)? - - func buildWithQRCode(qrCodeData: QrCodeData, oidcConfiguration: OIDCConfigurationProxy, progressListener: SDKListener) async throws -> ClientProtocol { - if let error = buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerThrowableError { - throw error - } - buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerCallsCount += 1 - buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReceivedArguments = (qrCodeData: qrCodeData, oidcConfiguration: oidcConfiguration, progressListener: progressListener) - DispatchQueue.main.async { - self.buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReceivedInvocations.append((qrCodeData: qrCodeData, oidcConfiguration: oidcConfiguration, progressListener: progressListener)) - } - if let buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerClosure = buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerClosure { - return try await buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerClosure(qrCodeData, oidcConfiguration, progressListener) - } else { - return buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReturnValue - } - } } class BannedRoomProxyMock: BannedRoomProxyProtocol, @unchecked Sendable { var info: BaseRoomInfoProxyProtocol { diff --git a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift index d9df93098..680191a64 100644 --- a/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift @@ -3031,6 +3031,52 @@ open class ClientSDKMock: MatrixRustSDK.Client, @unchecked Sendable { try await loginWithOidcCallbackCallbackUrlClosure?(callbackUrl) } + //MARK: - loginWithQrCode + + open var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerThrowableError: Error? + var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = 0 + open var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerCallsCount: Int { + get { + if Thread.isMainThread { + return loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = newValue + } + } + } + } + open var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerCalled: Bool { + return loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerCallsCount > 0 + } + open var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedArguments: (qrCodeData: QrCodeData, oidcConfiguration: OidcConfiguration, progressListener: QrLoginProgressListener)? + open var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedInvocations: [(qrCodeData: QrCodeData, oidcConfiguration: OidcConfiguration, progressListener: QrLoginProgressListener)] = [] + open var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerClosure: ((QrCodeData, OidcConfiguration, QrLoginProgressListener) async throws -> Void)? + + open override func loginWithQrCode(qrCodeData: QrCodeData, oidcConfiguration: OidcConfiguration, progressListener: QrLoginProgressListener) async throws { + if let error = loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerThrowableError { + throw error + } + loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerCallsCount += 1 + loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedArguments = (qrCodeData: qrCodeData, oidcConfiguration: oidcConfiguration, progressListener: progressListener) + DispatchQueue.main.async { + self.loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedInvocations.append((qrCodeData: qrCodeData, oidcConfiguration: oidcConfiguration, progressListener: progressListener)) + } + try await loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerClosure?(qrCodeData, oidcConfiguration, progressListener) + } + //MARK: - logout open var logoutThrowableError: Error? @@ -5637,81 +5683,6 @@ open class ClientBuilderSDKMock: MatrixRustSDK.ClientBuilder, @unchecked Sendabl } } - //MARK: - buildWithQrCode - - open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerThrowableError: Error? - var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = 0 - open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerCallsCount: Int { - get { - if Thread.isMainThread { - return buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount - } else { - var returnValue: Int? = nil - DispatchQueue.main.sync { - returnValue = buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount - } - - return returnValue! - } - } - set { - if Thread.isMainThread { - buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = newValue - } else { - DispatchQueue.main.sync { - buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = newValue - } - } - } - } - open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerCalled: Bool { - return buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerCallsCount > 0 - } - open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedArguments: (qrCodeData: QrCodeData, oidcConfiguration: OidcConfiguration, progressListener: QrLoginProgressListener)? - open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedInvocations: [(qrCodeData: QrCodeData, oidcConfiguration: OidcConfiguration, progressListener: QrLoginProgressListener)] = [] - - var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue: Client! - open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerReturnValue: Client! { - get { - if Thread.isMainThread { - return buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue - } else { - var returnValue: Client? = nil - DispatchQueue.main.sync { - returnValue = buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue - } - - return returnValue! - } - } - set { - if Thread.isMainThread { - buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue = newValue - } else { - DispatchQueue.main.sync { - buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue = newValue - } - } - } - } - open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerClosure: ((QrCodeData, OidcConfiguration, QrLoginProgressListener) async throws -> Client)? - - open override func buildWithQrCode(qrCodeData: QrCodeData, oidcConfiguration: OidcConfiguration, progressListener: QrLoginProgressListener) async throws -> Client { - if let error = buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerThrowableError { - throw error - } - buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerCallsCount += 1 - buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedArguments = (qrCodeData: qrCodeData, oidcConfiguration: oidcConfiguration, progressListener: progressListener) - DispatchQueue.main.async { - self.buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedInvocations.append((qrCodeData: qrCodeData, oidcConfiguration: oidcConfiguration, progressListener: progressListener)) - } - if let buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerClosure = buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerClosure { - return try await buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerClosure(qrCodeData, oidcConfiguration, progressListener) - } else { - return buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerReturnValue - } - } - //MARK: - crossProcessStoreLocksHolderName var crossProcessStoreLocksHolderNameHolderNameUnderlyingCallsCount = 0 diff --git a/ElementX/Sources/Services/Authentication/AuthenticationClientBuilder.swift b/ElementX/Sources/Services/Authentication/AuthenticationClientBuilder.swift index 63363f96b..3746b4383 100644 --- a/ElementX/Sources/Services/Authentication/AuthenticationClientBuilder.swift +++ b/ElementX/Sources/Services/Authentication/AuthenticationClientBuilder.swift @@ -11,9 +11,6 @@ import MatrixRustSDK // sourcery: AutoMockable protocol AuthenticationClientBuilderProtocol { func build(homeserverAddress: String) async throws -> ClientProtocol - func buildWithQRCode(qrCodeData: QrCodeData, - oidcConfiguration: OIDCConfigurationProxy, - progressListener: SDKListener) async throws -> ClientProtocol } /// A wrapper around `ClientBuilder` to share reusable code between Normal and QR logins. @@ -30,15 +27,6 @@ struct AuthenticationClientBuilder: AuthenticationClientBuilderProtocol { try await makeClientBuilder().serverNameOrHomeserverUrl(serverNameOrUrl: homeserverAddress).build() } - /// Builds a Client, authenticating with the given QR code data. - func buildWithQRCode(qrCodeData: QrCodeData, - oidcConfiguration: OIDCConfigurationProxy, - progressListener: SDKListener) async throws -> ClientProtocol { - try await makeClientBuilder().buildWithQrCode(qrCodeData: qrCodeData, - oidcConfiguration: oidcConfiguration.rustValue, - progressListener: progressListener) - } - // MARK: - Private /// The base builder configuration used for authentication within the app. diff --git a/ElementX/Sources/Services/QRCode/QRCodeLoginService.swift b/ElementX/Sources/Services/QRCode/QRCodeLoginService.swift index 319fe2546..3ff3cdc59 100644 --- a/ElementX/Sources/Services/QRCode/QRCodeLoginService.swift +++ b/ElementX/Sources/Services/QRCode/QRCodeLoginService.swift @@ -58,9 +58,10 @@ final class QRCodeLoginService: QRCodeLoginServiceProtocol { } do { - let client = try await makeClientBuilder().buildWithQRCode(qrCodeData: qrData, - oidcConfiguration: appSettings.oidcConfiguration, - progressListener: listener) + let client = try await makeClientBuilder().build(homeserverAddress: scannedServerName) + try await client.loginWithQrCode(qrCodeData: qrData, + oidcConfiguration: appSettings.oidcConfiguration.rustValue, + progressListener: listener) MXLog.info("Sliding sync: \(client.slidingSyncVersion())") return await userSession(for: client) } catch let error as HumanQrLoginError { diff --git a/UnitTests/Sources/AuthenticationStartScreenViewModelTests.swift b/UnitTests/Sources/AuthenticationStartScreenViewModelTests.swift index 19e398af0..7aead3e0c 100644 --- a/UnitTests/Sources/AuthenticationStartScreenViewModelTests.swift +++ b/UnitTests/Sources/AuthenticationStartScreenViewModelTests.swift @@ -137,8 +137,7 @@ class AuthenticationStartScreenViewModelTests: XCTestCase { client = ClientSDKMock(configuration: .init(oidcLoginURL: supportsOIDC ? "https://account.company.com/authorize" : nil, supportsOIDCCreatePrompt: false, supportsPasswordLogin: true)) - let configuration = AuthenticationClientBuilderMock.Configuration(homeserverClients: ["company.com": client], - qrCodeClient: client) + let configuration = AuthenticationClientBuilderMock.Configuration(homeserverClients: ["company.com": client]) clientBuilderFactory = AuthenticationClientBuilderFactoryMock(configuration: .init(builderConfiguration: configuration)) authenticationService = AuthenticationService(userSessionStore: UserSessionStoreMock(configuration: .init()), diff --git a/UnitTests/Sources/ServerConfirmationScreenViewModelTests.swift b/UnitTests/Sources/ServerConfirmationScreenViewModelTests.swift index e8715d72a..621ab402c 100644 --- a/UnitTests/Sources/ServerConfirmationScreenViewModelTests.swift +++ b/UnitTests/Sources/ServerConfirmationScreenViewModelTests.swift @@ -316,8 +316,7 @@ class ServerConfirmationScreenViewModelTests: XCTestCase { client = ClientSDKMock(configuration: .init(oidcLoginURL: supportsOIDC ? "https://account.matrix.org/authorize" : nil, supportsOIDCCreatePrompt: supportsOIDCCreatePrompt, supportsPasswordLogin: supportsPasswordLogin)) - let configuration = AuthenticationClientBuilderMock.Configuration(homeserverClients: ["matrix.org": client], - qrCodeClient: client) + let configuration = AuthenticationClientBuilderMock.Configuration(homeserverClients: ["matrix.org": client]) clientBuilderFactory = AuthenticationClientBuilderFactoryMock(configuration: .init(builderConfiguration: configuration)) service = AuthenticationService(userSessionStore: UserSessionStoreMock(configuration: .init()), diff --git a/project.yml b/project.yml index 97a90b4ad..c237f1b56 100644 --- a/project.yml +++ b/project.yml @@ -65,7 +65,7 @@ packages: # Element/Matrix dependencies MatrixRustSDK: url: https://github.com/element-hq/matrix-rust-components-swift - exactVersion: 25.07.10 + exactVersion: 25.07.14-2 # path: ../matrix-rust-sdk Compound: url: https://github.com/element-hq/compound-ios