mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 18:21:00 +00:00
Speedup status context load
This commit is contained in:
parent
4143e82fbc
commit
504f93fab0
1 changed files with 14 additions and 4 deletions
|
@ -55,17 +55,27 @@ class StatusDetailViewModel: ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
struct ContextData {
|
||||
let status: Status
|
||||
let context: StatusContext
|
||||
}
|
||||
|
||||
private func fetchStatusDetail() async {
|
||||
guard let client, let statusId else { return }
|
||||
do {
|
||||
let status: Status = try await client.get(endpoint: Statuses.status(id: statusId))
|
||||
let context: StatusContext = try await client.get(endpoint: Statuses.context(id: statusId))
|
||||
state = .display(status: status, context: context)
|
||||
title = "Post from \(status.account.displayNameWithoutEmojis)"
|
||||
let data = try await fetchContextData(client: client, statusId: statusId)
|
||||
state = .display(status: data.status, context: data.context)
|
||||
title = "Post from \(data.status.account.displayNameWithoutEmojis)"
|
||||
} catch {
|
||||
state = .error(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private func fetchContextData(client: Client, statusId: String) async throws -> ContextData {
|
||||
async let status: Status = client.get(endpoint: Statuses.status(id: statusId))
|
||||
async let context: StatusContext = client.get(endpoint: Statuses.context(id: statusId))
|
||||
return try await .init(status: status, context: context)
|
||||
}
|
||||
|
||||
func handleEvent(event: any StreamEvent, currentAccount: Account?) {
|
||||
if let event = event as? StreamEventUpdate,
|
||||
|
|
Loading…
Reference in a new issue