From aa9a6ee7013d350b3ead5a9f296e3487d01716e5 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Fri, 2 Jun 2023 11:10:29 +0200 Subject: [PATCH] Make account switching work again --- Mastodon/Coordinator/SceneCoordinator.swift | 2 +- .../Sources/MastodonCore/AuthenticationServiceProvider.swift | 4 ++-- .../Sources/MastodonCore/Service/AuthenticationService.swift | 2 +- ShareActionExtension/Scene/ShareViewController.swift | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Mastodon/Coordinator/SceneCoordinator.swift b/Mastodon/Coordinator/SceneCoordinator.swift index 496808d1f..bd7ae4894 100644 --- a/Mastodon/Coordinator/SceneCoordinator.swift +++ b/Mastodon/Coordinator/SceneCoordinator.swift @@ -217,7 +217,7 @@ extension SceneCoordinator { let rootViewController: UIViewController do { - let _authentication = AuthenticationServiceProvider.shared.authentications.first + let _authentication = AuthenticationServiceProvider.shared.authenticationSortedByActivation().first let _authContext = _authentication.flatMap { AuthContext(authentication: $0) } self.authContext = _authContext diff --git a/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift b/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift index 877f1211c..5a9c77228 100644 --- a/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift +++ b/MastodonSDK/Sources/MastodonCore/AuthenticationServiceProvider.swift @@ -50,8 +50,8 @@ public extension AuthenticationServiceProvider { authentications.first(where: { $0.userAccessToken == userAccessToken }) } - func sortByActivation() { // fixme: why do we need this? - authentications = authentications.sorted(by: { $0.activedAt > $1.activedAt }) + func authenticationSortedByActivation() -> [MastodonAuthentication] { // fixme: why do we need this? + return authentications.sorted(by: { $0.activedAt > $1.activedAt }) } func restore() { diff --git a/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift b/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift index b3ad468cc..d6024faad 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift @@ -119,7 +119,7 @@ public final class AuthenticationService: NSObject { } .assign(to: &$mastodonAuthenticationBoxes) - AuthenticationServiceProvider.shared.sortByActivation() + AuthenticationServiceProvider.shared.authentications = AuthenticationServiceProvider.shared.authenticationSortedByActivation() } } diff --git a/ShareActionExtension/Scene/ShareViewController.swift b/ShareActionExtension/Scene/ShareViewController.swift index 8ed018c99..6b2ed1323 100644 --- a/ShareActionExtension/Scene/ShareViewController.swift +++ b/ShareActionExtension/Scene/ShareViewController.swift @@ -179,8 +179,7 @@ extension ShareViewController { extension ShareViewController { private func setupAuthContext() throws -> AuthContext? { - AuthenticationServiceProvider.shared.sortByActivation() - let _authentication = AuthenticationServiceProvider.shared.authentications.first + let _authentication = AuthenticationServiceProvider.shared.authenticationSortedByActivation().first let _authContext = _authentication.flatMap { AuthContext(authentication: $0) } return _authContext }