More readable code

This commit is contained in:
Lumaa 2024-01-13 13:15:35 +01:00
parent ac35ec0c2e
commit 1010db0f4d
1 changed files with 21 additions and 9 deletions

View File

@ -92,17 +92,14 @@ struct AccountView: View {
initialFollowing = isFollowing
}
.refreshable {
if let client = accountManager.getClient() {
if let ref: Account = try? await client.get(endpoint: Accounts.accounts(id: account.id)) {
account = ref
await updateRelationship()
loadingStatuses = true
statuses = try? await client.get(endpoint: Accounts.statuses(id: account.id, sinceId: nil, tag: nil, onlyMedia: nil, excludeReplies: nil, pinned: nil))
statusesPinned = try? await client.get(endpoint: Accounts.statuses(id: account.id, sinceId: nil, tag: nil, onlyMedia: nil, excludeReplies: nil, pinned: true))
loadingStatuses = false
if isCurrent {
guard let client = accountManager.getClient() else { return }
if let acc: Account = try? await client.get(endpoint: Accounts.verifyCredentials) {
account = acc
}
}
await reloadUser()
}
.background(Color.appBackground)
.navigationBarTitleDisplayMode(.inline)
@ -239,6 +236,21 @@ struct AccountView: View {
}
}
func reloadUser() async {
if let client = accountManager.getClient() {
let userAcc = accountManager.getAccount()
if let ref: Account = try? await client.get(endpoint: Accounts.accounts(id: isCurrent && userAcc != nil ? userAcc!.id : account.id)) {
account = ref
await updateRelationship()
loadingStatuses = true
statuses = try? await client.get(endpoint: Accounts.statuses(id: account.id, sinceId: nil, tag: nil, onlyMedia: nil, excludeReplies: nil, pinned: nil))
statusesPinned = try? await client.get(endpoint: Accounts.statuses(id: account.id, sinceId: nil, tag: nil, onlyMedia: nil, excludeReplies: nil, pinned: true))
loadingStatuses = false
}
}
}
func updateRelationship() async {
if let client = accountManager.getClient() {
if let currentAccount: Account = try? await client.get(endpoint: Accounts.verifyCredentials) {