2022-06-09 18:09:28 +08:00
|
|
|
//
|
|
|
|
// Account.swift
|
|
|
|
// MastodonIntent
|
|
|
|
//
|
|
|
|
// Created by MainasuK on 2022-6-9.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import Intents
|
2022-09-30 19:28:09 +08:00
|
|
|
import MastodonCore
|
2022-06-09 18:09:28 +08:00
|
|
|
|
|
|
|
extension Account {
|
|
|
|
|
|
|
|
@MainActor
|
2024-11-19 09:39:18 -05:00
|
|
|
static func loadFromCache() -> [Account] {
|
|
|
|
let accounts = AuthenticationServiceProvider.shared.mastodonAuthenticationBoxes.compactMap { authBox -> Account? in
|
|
|
|
guard let authenticatedAccount = authBox.cachedAccount else {
|
2024-01-05 11:29:25 +01:00
|
|
|
return nil
|
2022-06-09 18:09:28 +08:00
|
|
|
}
|
2024-01-05 11:29:25 +01:00
|
|
|
let account = Account(
|
2024-11-19 09:39:18 -05:00
|
|
|
identifier: authBox.authentication.identifier.uuidString,
|
2024-01-05 11:29:25 +01:00
|
|
|
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 18:09:28 +08:00
|
|
|
|
|
|
|
return accounts
|
|
|
|
}
|
2024-01-05 11:29:25 +01:00
|
|
|
|
2022-06-09 18:09:28 +08:00
|
|
|
}
|