Fix PR remarks

This commit is contained in:
ismailgulek
2022-06-09 11:43:12 +03:00
parent b5b7814138
commit e2927ac206
8 changed files with 33 additions and 28 deletions
@@ -21,9 +21,9 @@ protocol SessionCreatorProtocol {
/// - Parameters:
/// - credentials: The `MXCredentials` for the account.
/// - client: The client that completed the authentication.
/// - resetOthers: Flag to reset other accounts.
/// - removeOtherAccounts: Flag to remove other accounts than the account specified with the `credentials.userId`.
/// - Returns: A new `MXSession` for the account.
func createSession(credentials: MXCredentials, client: AuthenticationRestClient, resetOthers: Bool) -> MXSession
func createSession(credentials: MXCredentials, client: AuthenticationRestClient, removeOtherAccounts: Bool) -> MXSession
}
/// A struct that provides common functionality to create a new session.
@@ -35,20 +35,23 @@ struct SessionCreator: SessionCreatorProtocol {
self.accountManager = accountManager
}
func createSession(credentials: MXCredentials, client: AuthenticationRestClient, resetOthers: Bool) -> MXSession {
func createSession(credentials: MXCredentials, client: AuthenticationRestClient, removeOtherAccounts: Bool) -> MXSession {
// Use identity server provided in the client
if credentials.identityServer == nil {
credentials.identityServer = client.identityServer
}
if removeOtherAccounts {
let otherAccounts = accountManager.accounts.filter({ $0.mxCredentials.userId != credentials.userId })
for account in otherAccounts {
accountManager.removeAccount(account, completion: nil)
}
}
if let account = accountManager.account(forUserId: credentials.userId) {
accountManager.hydrateAccount(account, with: credentials)
return account.mxSession
} else {
if resetOthers {
accountManager.logout(completion: nil)
}
let account = MXKAccount(credentials: credentials)
// set identity server of the new account