2022-12-30 08:36:22 +01:00
|
|
|
import SwiftUI
|
|
|
|
import Models
|
|
|
|
import Network
|
|
|
|
|
|
|
|
@MainActor
|
|
|
|
public class AppAccountViewModel: ObservableObject {
|
|
|
|
let appAccount: AppAccount
|
|
|
|
let client: Client
|
|
|
|
|
|
|
|
@Published var account: Account?
|
|
|
|
|
2023-01-10 06:58:50 +01:00
|
|
|
var acct: String {
|
|
|
|
"@\(account?.acct ?? "...")@\(appAccount.server)"
|
|
|
|
}
|
|
|
|
|
2022-12-30 08:36:22 +01:00
|
|
|
init(appAccount: AppAccount) {
|
|
|
|
self.appAccount = appAccount
|
|
|
|
self.client = .init(server: appAccount.server, oauthToken: appAccount.oauthToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchAccount() async {
|
|
|
|
do {
|
|
|
|
account = try await client.get(endpoint: Accounts.verifyCredentials)
|
|
|
|
} catch {
|
|
|
|
print(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|