Put the session creator on the main actor instead.

This covers all login and registration options.
This commit is contained in:
Doug
2022-09-16 12:31:25 +01:00
parent f87aff8efc
commit e15e437616
5 changed files with 13 additions and 10 deletions
@@ -51,7 +51,7 @@ class LoginWizard {
/// - deviceID: The device ID, optional. If not provided or nil, the server will generate one.
/// - removeOtherAccounts: If set to true, existing accounts with different user identifiers will be removed.
/// - Returns: An `MXSession` if the login is successful.
@MainActor func login(login: String,
func login(login: String,
password: String,
initialDeviceName: String,
deviceID: String? = nil,
@@ -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.
@@ -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
@@ -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
@@ -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
}
@@ -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 {