Use accounts for shortcut-extension (IOS-192)

This is broken atm, see #1204
This commit is contained in:
Nathan Mattes 2024-01-05 11:29:25 +01:00
parent 58501da5fa
commit c3d40d260d
2 changed files with 18 additions and 23 deletions

View File

@ -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<Account> {
let accounts = try await Account.fetch(in: managedObjectContext)
let accounts = try await Account.fetch()
return .init(items: accounts)
}

View File

@ -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) }