mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2024-12-12 08:36:02 +01:00
c3d40d260d
This is broken atm, see #1204
48 lines
1.4 KiB
Swift
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
|
|
}
|
|
|
|
}
|