diff --git a/Mastodon/Coordinator/SceneCoordinator.swift b/Mastodon/Coordinator/SceneCoordinator.swift index ae8d81d25..58323cc4e 100644 --- a/Mastodon/Coordinator/SceneCoordinator.swift +++ b/Mastodon/Coordinator/SceneCoordinator.swift @@ -216,7 +216,7 @@ extension SceneCoordinator { let rootViewController: UIViewController do { - let request = MastodonAuthentication.sortedFetchRequest + let request = MastodonAuthentication.activeSortedFetchRequest // use active order let _authentication = try appContext.managedObjectContext.fetch(request).first let _authContext = _authentication.flatMap { AuthContext(authentication: $0) } self.authContext = _authContext diff --git a/Mastodon/Scene/Account/AccountListViewModel.swift b/Mastodon/Scene/Account/AccountListViewModel.swift index 17eab07ea..e0aaf97fc 100644 --- a/Mastodon/Scene/Account/AccountListViewModel.swift +++ b/Mastodon/Scene/Account/AccountListViewModel.swift @@ -50,6 +50,12 @@ final class AccountListViewModel: NSObject { // end init mastodonAuthenticationFetchedResultsController.delegate = self + do { + try mastodonAuthenticationFetchedResultsController.performFetch() + authentications = mastodonAuthenticationFetchedResultsController.fetchedObjects?.compactMap { $0.asRecrod } ?? [] + } catch { + assertionFailure(error.localizedDescription) + } $authentications .receive(on: DispatchQueue.main) diff --git a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/MastodonAuthentication.swift b/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/MastodonAuthentication.swift index 1c5c40851..2d8a97fad 100644 --- a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/MastodonAuthentication.swift +++ b/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/MastodonAuthentication.swift @@ -148,6 +148,18 @@ extension MastodonAuthentication: Managed { public static var defaultSortDescriptors: [NSSortDescriptor] { return [NSSortDescriptor(keyPath: \MastodonAuthentication.createdAt, ascending: false)] } + + public static var activeSortDescriptors: [NSSortDescriptor] { + return [NSSortDescriptor(keyPath: \MastodonAuthentication.activedAt, ascending: false)] + } +} + +extension MastodonAuthentication { + public static var activeSortedFetchRequest: NSFetchRequest { + let request = NSFetchRequest(entityName: entityName) + request.sortDescriptors = activeSortDescriptors + return request + } } extension MastodonAuthentication {