1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-12 08:36:02 +01:00
mastodon-app-ufficiale-ipho.../MastodonIntent/Model/Account+Fetch.swift
Nathan Mattes c3d40d260d Use accounts for shortcut-extension (IOS-192)
This is broken atm, see #1204
2024-01-05 11:29:25 +01:00

48 lines
1.4 KiB
Swift

//
// Account.swift
// MastodonIntent
//
// Created by MainasuK on 2022-6-9.
//
import Foundation
import CoreData
import CoreDataStack
import Intents
import MastodonCore
extension Account {
@MainActor
static func fetch() async throws -> [Account] {
let accounts = AuthenticationServiceProvider.shared.authentications.compactMap { mastodonAuthentication -> Account? in
guard let authenticatedAccount = mastodonAuthentication.account() else {
return nil
}
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() throws -> [MastodonAuthentication] {
let identifiers = self
.compactMap { $0.identifier }
.compactMap { UUID(uuidString: $0) }
let results = AuthenticationServiceProvider.shared.authentications.filter({ identifiers.contains($0.identifier) })
return results
}
}