Skip to content

Commit de4f05f

Browse files
authored
Update the SDK and build a client before logging in with a QR code. (#4320)
1 parent e461651 commit de4f05f

File tree

10 files changed

+56
-175
lines changed

10 files changed

+56
-175
lines changed

ElementX.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8771,7 +8771,7 @@
87718771
repositoryURL = "https://github.com/element-hq/matrix-rust-components-swift";
87728772
requirement = {
87738773
kind = exactVersion;
8774-
version = 25.07.10;
8774+
version = "25.07.14-2";
87758775
};
87768776
};
87778777
701C7BEF8F70F7A83E852DCC /* XCRemoteSwiftPackageReference "GZIP" */ = {

ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ElementX/Sources/Mocks/AuthenticationClientBuilderMock.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ extension AuthenticationClientBuilderMock {
3131
supportsOIDCCreatePrompt: false,
3232
supportsPasswordLogin: false))
3333
]
34-
var qrCodeClient = ClientSDKMock(configuration: .init())
3534
}
3635

3736
convenience init(configuration: Configuration) {
@@ -43,7 +42,5 @@ extension AuthenticationClientBuilderMock {
4342
}
4443
return client
4544
}
46-
47-
buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReturnValue = configuration.qrCodeClient
4845
}
4946
}

ElementX/Sources/Mocks/Generated/GeneratedMocks.swift

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,80 +1972,6 @@ class AuthenticationClientBuilderMock: AuthenticationClientBuilderProtocol, @unc
19721972
return buildHomeserverAddressReturnValue
19731973
}
19741974
}
1975-
//MARK: - buildWithQRCode
1976-
1977-
var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerThrowableError: Error?
1978-
var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = 0
1979-
var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerCallsCount: Int {
1980-
get {
1981-
if Thread.isMainThread {
1982-
return buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount
1983-
} else {
1984-
var returnValue: Int? = nil
1985-
DispatchQueue.main.sync {
1986-
returnValue = buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount
1987-
}
1988-
1989-
return returnValue!
1990-
}
1991-
}
1992-
set {
1993-
if Thread.isMainThread {
1994-
buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = newValue
1995-
} else {
1996-
DispatchQueue.main.sync {
1997-
buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = newValue
1998-
}
1999-
}
2000-
}
2001-
}
2002-
var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerCalled: Bool {
2003-
return buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerCallsCount > 0
2004-
}
2005-
var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReceivedArguments: (qrCodeData: QrCodeData, oidcConfiguration: OIDCConfigurationProxy, progressListener: SDKListener<QrLoginProgress>)?
2006-
var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReceivedInvocations: [(qrCodeData: QrCodeData, oidcConfiguration: OIDCConfigurationProxy, progressListener: SDKListener<QrLoginProgress>)] = []
2007-
2008-
var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue: ClientProtocol!
2009-
var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReturnValue: ClientProtocol! {
2010-
get {
2011-
if Thread.isMainThread {
2012-
return buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue
2013-
} else {
2014-
var returnValue: ClientProtocol? = nil
2015-
DispatchQueue.main.sync {
2016-
returnValue = buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue
2017-
}
2018-
2019-
return returnValue!
2020-
}
2021-
}
2022-
set {
2023-
if Thread.isMainThread {
2024-
buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue = newValue
2025-
} else {
2026-
DispatchQueue.main.sync {
2027-
buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue = newValue
2028-
}
2029-
}
2030-
}
2031-
}
2032-
var buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerClosure: ((QrCodeData, OIDCConfigurationProxy, SDKListener<QrLoginProgress>) async throws -> ClientProtocol)?
2033-
2034-
func buildWithQRCode(qrCodeData: QrCodeData, oidcConfiguration: OIDCConfigurationProxy, progressListener: SDKListener<QrLoginProgress>) async throws -> ClientProtocol {
2035-
if let error = buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerThrowableError {
2036-
throw error
2037-
}
2038-
buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerCallsCount += 1
2039-
buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReceivedArguments = (qrCodeData: qrCodeData, oidcConfiguration: oidcConfiguration, progressListener: progressListener)
2040-
DispatchQueue.main.async {
2041-
self.buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReceivedInvocations.append((qrCodeData: qrCodeData, oidcConfiguration: oidcConfiguration, progressListener: progressListener))
2042-
}
2043-
if let buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerClosure = buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerClosure {
2044-
return try await buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerClosure(qrCodeData, oidcConfiguration, progressListener)
2045-
} else {
2046-
return buildWithQRCodeQrCodeDataOidcConfigurationProgressListenerReturnValue
2047-
}
2048-
}
20491975
}
20501976
class BannedRoomProxyMock: BannedRoomProxyProtocol, @unchecked Sendable {
20511977
var info: BaseRoomInfoProxyProtocol {

ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift

Lines changed: 46 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,6 +3031,52 @@ open class ClientSDKMock: MatrixRustSDK.Client, @unchecked Sendable {
30313031
try await loginWithOidcCallbackCallbackUrlClosure?(callbackUrl)
30323032
}
30333033

3034+
//MARK: - loginWithQrCode
3035+
3036+
open var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerThrowableError: Error?
3037+
var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = 0
3038+
open var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerCallsCount: Int {
3039+
get {
3040+
if Thread.isMainThread {
3041+
return loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount
3042+
} else {
3043+
var returnValue: Int? = nil
3044+
DispatchQueue.main.sync {
3045+
returnValue = loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount
3046+
}
3047+
3048+
return returnValue!
3049+
}
3050+
}
3051+
set {
3052+
if Thread.isMainThread {
3053+
loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = newValue
3054+
} else {
3055+
DispatchQueue.main.sync {
3056+
loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = newValue
3057+
}
3058+
}
3059+
}
3060+
}
3061+
open var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerCalled: Bool {
3062+
return loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerCallsCount > 0
3063+
}
3064+
open var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedArguments: (qrCodeData: QrCodeData, oidcConfiguration: OidcConfiguration, progressListener: QrLoginProgressListener)?
3065+
open var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedInvocations: [(qrCodeData: QrCodeData, oidcConfiguration: OidcConfiguration, progressListener: QrLoginProgressListener)] = []
3066+
open var loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerClosure: ((QrCodeData, OidcConfiguration, QrLoginProgressListener) async throws -> Void)?
3067+
3068+
open override func loginWithQrCode(qrCodeData: QrCodeData, oidcConfiguration: OidcConfiguration, progressListener: QrLoginProgressListener) async throws {
3069+
if let error = loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerThrowableError {
3070+
throw error
3071+
}
3072+
loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerCallsCount += 1
3073+
loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedArguments = (qrCodeData: qrCodeData, oidcConfiguration: oidcConfiguration, progressListener: progressListener)
3074+
DispatchQueue.main.async {
3075+
self.loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedInvocations.append((qrCodeData: qrCodeData, oidcConfiguration: oidcConfiguration, progressListener: progressListener))
3076+
}
3077+
try await loginWithQrCodeQrCodeDataOidcConfigurationProgressListenerClosure?(qrCodeData, oidcConfiguration, progressListener)
3078+
}
3079+
30343080
//MARK: - logout
30353081

30363082
open var logoutThrowableError: Error?
@@ -5637,81 +5683,6 @@ open class ClientBuilderSDKMock: MatrixRustSDK.ClientBuilder, @unchecked Sendabl
56375683
}
56385684
}
56395685

5640-
//MARK: - buildWithQrCode
5641-
5642-
open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerThrowableError: Error?
5643-
var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = 0
5644-
open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerCallsCount: Int {
5645-
get {
5646-
if Thread.isMainThread {
5647-
return buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount
5648-
} else {
5649-
var returnValue: Int? = nil
5650-
DispatchQueue.main.sync {
5651-
returnValue = buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount
5652-
}
5653-
5654-
return returnValue!
5655-
}
5656-
}
5657-
set {
5658-
if Thread.isMainThread {
5659-
buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = newValue
5660-
} else {
5661-
DispatchQueue.main.sync {
5662-
buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingCallsCount = newValue
5663-
}
5664-
}
5665-
}
5666-
}
5667-
open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerCalled: Bool {
5668-
return buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerCallsCount > 0
5669-
}
5670-
open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedArguments: (qrCodeData: QrCodeData, oidcConfiguration: OidcConfiguration, progressListener: QrLoginProgressListener)?
5671-
open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedInvocations: [(qrCodeData: QrCodeData, oidcConfiguration: OidcConfiguration, progressListener: QrLoginProgressListener)] = []
5672-
5673-
var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue: Client!
5674-
open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerReturnValue: Client! {
5675-
get {
5676-
if Thread.isMainThread {
5677-
return buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue
5678-
} else {
5679-
var returnValue: Client? = nil
5680-
DispatchQueue.main.sync {
5681-
returnValue = buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue
5682-
}
5683-
5684-
return returnValue!
5685-
}
5686-
}
5687-
set {
5688-
if Thread.isMainThread {
5689-
buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue = newValue
5690-
} else {
5691-
DispatchQueue.main.sync {
5692-
buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerUnderlyingReturnValue = newValue
5693-
}
5694-
}
5695-
}
5696-
}
5697-
open var buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerClosure: ((QrCodeData, OidcConfiguration, QrLoginProgressListener) async throws -> Client)?
5698-
5699-
open override func buildWithQrCode(qrCodeData: QrCodeData, oidcConfiguration: OidcConfiguration, progressListener: QrLoginProgressListener) async throws -> Client {
5700-
if let error = buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerThrowableError {
5701-
throw error
5702-
}
5703-
buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerCallsCount += 1
5704-
buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedArguments = (qrCodeData: qrCodeData, oidcConfiguration: oidcConfiguration, progressListener: progressListener)
5705-
DispatchQueue.main.async {
5706-
self.buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerReceivedInvocations.append((qrCodeData: qrCodeData, oidcConfiguration: oidcConfiguration, progressListener: progressListener))
5707-
}
5708-
if let buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerClosure = buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerClosure {
5709-
return try await buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerClosure(qrCodeData, oidcConfiguration, progressListener)
5710-
} else {
5711-
return buildWithQrCodeQrCodeDataOidcConfigurationProgressListenerReturnValue
5712-
}
5713-
}
5714-
57155686
//MARK: - crossProcessStoreLocksHolderName
57165687

57175688
var crossProcessStoreLocksHolderNameHolderNameUnderlyingCallsCount = 0

ElementX/Sources/Services/Authentication/AuthenticationClientBuilder.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ import MatrixRustSDK
1111
// sourcery: AutoMockable
1212
protocol AuthenticationClientBuilderProtocol {
1313
func build(homeserverAddress: String) async throws -> ClientProtocol
14-
func buildWithQRCode(qrCodeData: QrCodeData,
15-
oidcConfiguration: OIDCConfigurationProxy,
16-
progressListener: SDKListener<QrLoginProgress>) async throws -> ClientProtocol
1714
}
1815

1916
/// A wrapper around `ClientBuilder` to share reusable code between Normal and QR logins.
@@ -30,15 +27,6 @@ struct AuthenticationClientBuilder: AuthenticationClientBuilderProtocol {
3027
try await makeClientBuilder().serverNameOrHomeserverUrl(serverNameOrUrl: homeserverAddress).build()
3128
}
3229

33-
/// Builds a Client, authenticating with the given QR code data.
34-
func buildWithQRCode(qrCodeData: QrCodeData,
35-
oidcConfiguration: OIDCConfigurationProxy,
36-
progressListener: SDKListener<QrLoginProgress>) async throws -> ClientProtocol {
37-
try await makeClientBuilder().buildWithQrCode(qrCodeData: qrCodeData,
38-
oidcConfiguration: oidcConfiguration.rustValue,
39-
progressListener: progressListener)
40-
}
41-
4230
// MARK: - Private
4331

4432
/// The base builder configuration used for authentication within the app.

ElementX/Sources/Services/QRCode/QRCodeLoginService.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ final class QRCodeLoginService: QRCodeLoginServiceProtocol {
5858
}
5959

6060
do {
61-
let client = try await makeClientBuilder().buildWithQRCode(qrCodeData: qrData,
62-
oidcConfiguration: appSettings.oidcConfiguration,
63-
progressListener: listener)
61+
let client = try await makeClientBuilder().build(homeserverAddress: scannedServerName)
62+
try await client.loginWithQrCode(qrCodeData: qrData,
63+
oidcConfiguration: appSettings.oidcConfiguration.rustValue,
64+
progressListener: listener)
6465
MXLog.info("Sliding sync: \(client.slidingSyncVersion())")
6566
return await userSession(for: client)
6667
} catch let error as HumanQrLoginError {

UnitTests/Sources/AuthenticationStartScreenViewModelTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ class AuthenticationStartScreenViewModelTests: XCTestCase {
137137
client = ClientSDKMock(configuration: .init(oidcLoginURL: supportsOIDC ? "https://account.company.com/authorize" : nil,
138138
supportsOIDCCreatePrompt: false,
139139
supportsPasswordLogin: true))
140-
let configuration = AuthenticationClientBuilderMock.Configuration(homeserverClients: ["company.com": client],
141-
qrCodeClient: client)
140+
let configuration = AuthenticationClientBuilderMock.Configuration(homeserverClients: ["company.com": client])
142141

143142
clientBuilderFactory = AuthenticationClientBuilderFactoryMock(configuration: .init(builderConfiguration: configuration))
144143
authenticationService = AuthenticationService(userSessionStore: UserSessionStoreMock(configuration: .init()),

UnitTests/Sources/ServerConfirmationScreenViewModelTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,7 @@ class ServerConfirmationScreenViewModelTests: XCTestCase {
316316
client = ClientSDKMock(configuration: .init(oidcLoginURL: supportsOIDC ? "https://account.matrix.org/authorize" : nil,
317317
supportsOIDCCreatePrompt: supportsOIDCCreatePrompt,
318318
supportsPasswordLogin: supportsPasswordLogin))
319-
let configuration = AuthenticationClientBuilderMock.Configuration(homeserverClients: ["matrix.org": client],
320-
qrCodeClient: client)
319+
let configuration = AuthenticationClientBuilderMock.Configuration(homeserverClients: ["matrix.org": client])
321320

322321
clientBuilderFactory = AuthenticationClientBuilderFactoryMock(configuration: .init(builderConfiguration: configuration))
323322
service = AuthenticationService(userSessionStore: UserSessionStoreMock(configuration: .init()),

project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ packages:
6565
# Element/Matrix dependencies
6666
MatrixRustSDK:
6767
url: https://github.com/element-hq/matrix-rust-components-swift
68-
exactVersion: 25.07.10
68+
exactVersion: 25.07.14-2
6969
# path: ../matrix-rust-sdk
7070
Compound:
7171
url: https://github.com/element-hq/compound-ios

0 commit comments

Comments
 (0)