Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix login crash on Xcode 14 builds #6728

Merged
merged 2 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class LoginWizard {
}

let credentials = try await client.login(parameters: parameters)
return sessionCreator.createSession(credentials: credentials,
client: client,
removeOtherAccounts: removeOtherAccounts)
return await sessionCreator.createSession(credentials: credentials,
client: client,
removeOtherAccounts: removeOtherAccounts)
}

/// Exchange a login token to an access token.
Expand All @@ -91,9 +91,9 @@ class LoginWizard {
func login(with token: String, removeOtherAccounts: Bool = false) async throws -> MXSession {
let parameters = LoginTokenParameters(token: token)
let credentials = try await client.login(parameters: parameters)
return sessionCreator.createSession(credentials: credentials,
client: client,
removeOtherAccounts: removeOtherAccounts)
return await sessionCreator.createSession(credentials: credentials,
client: client,
removeOtherAccounts: removeOtherAccounts)
}

/// Ask the homeserver to reset the user password. The password will not be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class RegistrationWizard {
do {
let response = try await client.register(parameters: parameters)
let credentials = MXCredentials(loginResponse: response, andDefaultCredentials: client.credentials)
return .success(sessionCreator.createSession(credentials: credentials, client: client, removeOtherAccounts: false))
return await .success(sessionCreator.createSession(credentials: credentials, client: client, removeOtherAccounts: false))
} catch {
let nsError = error as NSError

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ protocol SessionCreatorProtocol {
/// - client: The client that completed the authentication.
/// - removeOtherAccounts: Flag to remove other accounts than the account specified with the `credentials.userId`.
/// - Returns: A new `MXSession` for the account.
@MainActor
func createSession(credentials: MXCredentials, client: AuthenticationRestClient, removeOtherAccounts: Bool) -> MXSession
}

Expand All @@ -35,6 +36,7 @@ struct SessionCreator: SessionCreatorProtocol {
self.accountManager = accountManager
}

@MainActor
func createSession(credentials: MXCredentials, client: AuthenticationRestClient, removeOtherAccounts: Bool) -> MXSession {
// Use identity server provided in the client
if credentials.identityServer == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Foundation

struct MockSessionCreator: SessionCreatorProtocol {
/// Returns a basic session created from the supplied credentials. This prevents the app from setting up the account during tests.
@MainActor
func createSession(credentials: MXCredentials, client: AuthenticationRestClient, removeOtherAccounts: Bool) -> MXSession {
let client = MXRestClient(credentials: credentials,
unauthenticatedHandler: { _,_,_,_ in }) // The handler is expected if credentials are set.
Expand Down
4 changes: 2 additions & 2 deletions RiotTests/SessionCreatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import XCTest

class SessionCreatorTests: XCTestCase {

func testIdentityServer() throws {
func testIdentityServer() async throws {
let sessionCreator = SessionCreator(withAccountManager: .mock)

let mockIS = "mock_identity_server"
Expand All @@ -29,7 +29,7 @@ class SessionCreatorTests: XCTestCase {
accessToken: "mock_access_token")
let client = MXRestClient(credentials: credentials)
client.identityServer = mockIS
let session = sessionCreator.createSession(credentials: credentials, client: client, removeOtherAccounts: false)
let session = await sessionCreator.createSession(credentials: credentials, client: client, removeOtherAccounts: false)

XCTAssertEqual(credentials.identityServer, mockIS)
XCTAssertEqual(session.credentials.identityServer, mockIS)
Expand Down
1 change: 1 addition & 0 deletions changelog.d/6722.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix login crash on Xcode 14 builds