2022-06-09 12:09:28 +02:00
|
|
|
//
|
|
|
|
// Account.swift
|
|
|
|
// MastodonIntent
|
|
|
|
//
|
|
|
|
// Created by MainasuK on 2022-6-9.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import Intents
|
2022-09-30 13:28:09 +02:00
|
|
|
import MastodonCore
|
2022-06-09 12:09:28 +02:00
|
|
|
|
|
|
|
extension Account {
|
|
|
|
|
|
|
|
@MainActor
|
2024-01-05 11:29:25 +01:00
|
|
|
static func fetch() async throws -> [Account] {
|
|
|
|
let accounts = AuthenticationServiceProvider.shared.authentications.compactMap { mastodonAuthentication -> Account? in
|
|
|
|
guard let authenticatedAccount = mastodonAuthentication.account() else {
|
|
|
|
return nil
|
2022-06-09 12:09:28 +02:00
|
|
|
}
|
2024-01-05 11:29:25 +01:00
|
|
|
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
|
|
|
|
}
|
2022-06-09 12:09:28 +02:00
|
|
|
|
|
|
|
return accounts
|
|
|
|
}
|
2024-01-05 11:29:25 +01:00
|
|
|
|
2022-06-09 12:09:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extension Array where Element == Account {
|
2024-01-05 11:29:25 +01:00
|
|
|
func mastodonAuthentication() throws -> [MastodonAuthentication] {
|
2022-06-09 12:09:28 +02:00
|
|
|
let identifiers = self
|
|
|
|
.compactMap { $0.identifier }
|
|
|
|
.compactMap { UUID(uuidString: $0) }
|
2023-05-25 16:26:17 +02:00
|
|
|
let results = AuthenticationServiceProvider.shared.authentications.filter({ identifiers.contains($0.identifier) })
|
2022-06-09 12:09:28 +02:00
|
|
|
return results
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|