Fix race condition causing My Profile tab bar image to not be set

This commit is contained in:
Shadowfacts 2020-10-14 19:34:30 -04:00
parent 08045dd1e9
commit 5414f2329c
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 9 additions and 8 deletions

View File

@ -7,6 +7,7 @@
//
import UIKit
import Pachyderm
class MyProfileViewController: ProfileViewController {
@ -21,7 +22,7 @@ class MyProfileViewController: ProfileViewController {
DispatchQueue.main.async {
self.accountID = account.id
self.setAvatarTabBarImage()
self.setAvatarTabBarImage(account: account)
}
}
}
@ -38,12 +39,7 @@ class MyProfileViewController: ProfileViewController {
NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil)
}
private func setAvatarTabBarImage() {
guard let id = mastodonController.account?.id,
let account = mastodonController.persistentContainer.account(for: id) else {
return
}
private func setAvatarTabBarImage<Account: AccountProtocol>(account: Account) {
_ = ImageCache.avatars.get(account.avatar, completion: { [weak self] (data) in
guard let self = self, let data = data, let image = UIImage(data: data) else { return }
DispatchQueue.main.async {
@ -61,7 +57,12 @@ class MyProfileViewController: ProfileViewController {
}
@objc private func preferencesChanged() {
setAvatarTabBarImage()
guard let id = mastodonController.account?.id,
let account = mastodonController.persistentContainer.account(for: id) else {
return
}
setAvatarTabBarImage(account: account)
}
// MARK: - Interaction