2023-05-01 07:50:24 +02:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
|
|
|
// Licensed under the Apache License 2.0.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
import PixelfedKit
|
|
|
|
|
|
|
|
public class AccountFetcher {
|
|
|
|
public static let shared = AccountFetcher()
|
|
|
|
private init() { }
|
|
|
|
|
|
|
|
func fetchWidgetEntry() async throws -> [QRCodeWidgetEntry] {
|
|
|
|
let defaultSettings = ApplicationSettingsHandler.shared.get()
|
|
|
|
guard let accountId = defaultSettings.currentAccount else {
|
|
|
|
return [self.placeholder()]
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let account = AccountDataHandler.shared.getAccountData(accountId: accountId) else {
|
|
|
|
return [self.placeholder()]
|
|
|
|
}
|
|
|
|
|
|
|
|
let uiAvatar = await FileFetcher.shared.getImage(url: account.avatar)
|
|
|
|
|
|
|
|
return [
|
|
|
|
QRCodeWidgetEntry(date: Date(),
|
|
|
|
accountId: accountId,
|
2023-05-01 18:01:07 +02:00
|
|
|
acct: account.acct,
|
2023-05-01 07:50:24 +02:00
|
|
|
avatar: uiAvatar,
|
|
|
|
displayName: account.displayName,
|
|
|
|
profileUrl: account.url,
|
|
|
|
avatarUrl: account.avatar,
|
|
|
|
portfolioUrl: nil)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
func placeholder() -> QRCodeWidgetEntry {
|
|
|
|
QRCodeWidgetEntry(date: Date(),
|
|
|
|
accountId: "",
|
2023-05-01 18:01:07 +02:00
|
|
|
acct: "@caroline",
|
2023-05-01 07:50:24 +02:00
|
|
|
avatar: nil,
|
|
|
|
displayName: "Caroline Rick",
|
|
|
|
profileUrl: URL(string: "https://pixelfed.org"),
|
|
|
|
avatarUrl: nil,
|
|
|
|
portfolioUrl: nil)
|
|
|
|
}
|
|
|
|
}
|