From c3d40d260d575cca3666b00f34ea8389fdcdd9a0 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Fri, 5 Jan 2024 11:29:25 +0100 Subject: [PATCH] Use accounts for shortcut-extension (IOS-192) This is broken atm, see #1204 --- .../Handler/SendPostIntentHandler.swift | 4 +- MastodonIntent/Model/Account+Fetch.swift | 37 ++++++++----------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/MastodonIntent/Handler/SendPostIntentHandler.swift b/MastodonIntent/Handler/SendPostIntentHandler.swift index b457b1c91..0e37d63a8 100644 --- a/MastodonIntent/Handler/SendPostIntentHandler.swift +++ b/MastodonIntent/Handler/SendPostIntentHandler.swift @@ -59,7 +59,7 @@ extension SendPostIntentHandler: SendPostIntentHandling { } mastodonAuthentications = [authentication] } else { - mastodonAuthentications = try accounts.mastodonAuthentication(in: managedObjectContext) + mastodonAuthentications = try accounts.mastodonAuthentication() } let authenticationBoxes = mastodonAuthentications.map { authentication in @@ -149,7 +149,7 @@ extension SendPostIntentHandler: SendPostIntentHandling { } func provideAccountsOptionsCollection(for intent: SendPostIntent) async throws -> INObjectCollection { - let accounts = try await Account.fetch(in: managedObjectContext) + let accounts = try await Account.fetch() return .init(items: accounts) } diff --git a/MastodonIntent/Model/Account+Fetch.swift b/MastodonIntent/Model/Account+Fetch.swift index f3d8ee344..bdd9f412a 100644 --- a/MastodonIntent/Model/Account+Fetch.swift +++ b/MastodonIntent/Model/Account+Fetch.swift @@ -14,34 +14,29 @@ import MastodonCore extension Account { @MainActor - static func fetch(in managedObjectContext: NSManagedObjectContext) async throws -> [Account] { - // get accounts - let accounts: [Account] = try await managedObjectContext.perform { - let results = AuthenticationServiceProvider.shared.authentications - let accounts = results.compactMap { mastodonAuthentication -> Account? in - guard let user = mastodonAuthentication.user(in: managedObjectContext) else { - return nil - } - let account = Account( - identifier: mastodonAuthentication.identifier.uuidString, - display: user.displayNameWithFallback, - subtitle: user.acctWithDomain, - image: user.avatarImageURL().flatMap { INImage(url: $0) } - ) - account.name = user.displayNameWithFallback - account.username = user.acctWithDomain - return account + static func fetch() async throws -> [Account] { + let accounts = AuthenticationServiceProvider.shared.authentications.compactMap { mastodonAuthentication -> Account? in + guard let authenticatedAccount = mastodonAuthentication.account() else { + return nil } - return accounts - } // end managedObjectContext.perform + let account = Account( + identifier: mastodonAuthentication.identifier.uuidString, + display: authenticatedAccount.displayNameWithFallback, + subtitle: authenticatedAccount.acctWithDomain, + image: authenticatedAccount.avatarImageURL().flatMap { INImage(url: $0) } + ) + account.name = authenticatedAccount.displayNameWithFallback + account.username = authenticatedAccount.acctWithDomain + return account + } return accounts } - + } extension Array where Element == Account { - func mastodonAuthentication(in managedObjectContext: NSManagedObjectContext) throws -> [MastodonAuthentication] { + func mastodonAuthentication() throws -> [MastodonAuthentication] { let identifiers = self .compactMap { $0.identifier } .compactMap { UUID(uuidString: $0) }