Fix account switcher

This commit is contained in:
Thomas Ricouard 2023-02-16 08:38:34 +01:00
parent 9f894858ae
commit 64bee206b9

View File

@ -16,9 +16,6 @@ public class AppAccountViewModel: ObservableObject {
didSet { didSet {
if let account { if let account {
refreshAcct(account: account) refreshAcct(account: account)
Task {
await refreshAvatar(account: account)
}
} }
} }
} }
@ -44,9 +41,12 @@ public class AppAccountViewModel: ObservableObject {
roundedAvatar = Self.avatarsCache[appAccount.id] roundedAvatar = Self.avatarsCache[appAccount.id]
account = try await client.get(endpoint: Accounts.verifyCredentials) account = try await client.get(endpoint: Accounts.verifyCredentials)
Self.accountsCache[appAccount.id] = account Self.accountsCache[appAccount.id] = account
if let account {
await refreshAvatar(account: account)
}
} catch {} } catch {}
} }
@ -60,8 +60,7 @@ public class AppAccountViewModel: ObservableObject {
} }
private func refreshAvatar(account: Account) async { private func refreshAvatar(account: Account) async {
if roundedAvatar == nil, if let (data, _) = try? await URLSession.shared.data(from: account.avatar),
let (data, _) = try? await URLSession.shared.data(from: account.avatar),
let image = UIImage(data: data)?.roundedImage { let image = UIImage(data: data)?.roundedImage {
roundedAvatar = image roundedAvatar = image
Self.avatarsCache[account.id] = image Self.avatarsCache[account.id] = image