shannon 54d04aed4e Continue to make MastodonAuthenticationBox the standard form of passing user information
Further simplify the AuthenticationViewModel and the public interface of AuthenticationServiceProvider.

Publish currentActiveUser from AuthenticationServiceProvider instead of assuming all callers know to take the first in the list as the active one.

contributes to iOS-319
2024-11-19 12:09:55 -05:00

37 lines
1.0 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 loadFromCache() -> [Account] {
let accounts = AuthenticationServiceProvider.shared.mastodonAuthenticationBoxes.compactMap { authBox -> Account? in
guard let authenticatedAccount = authBox.cachedAccount else {
return nil
}
let account = Account(
identifier: authBox.authentication.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
}
}