Fix crash when loading account

This commit is contained in:
Shadowfacts 2022-04-26 22:11:19 -04:00
parent 20dab7c77a
commit 7465abe0a9
1 changed files with 17 additions and 3 deletions

View File

@ -120,12 +120,23 @@ class ProfileViewController: UIPageViewController {
let req = Client.getAccount(id: accountID) let req = Client.getAccount(id: accountID)
mastodonController.run(req) { [weak self] (response) in mastodonController.run(req) { [weak self] (response) in
guard let self = self else { return } guard let self = self else { return }
guard case let .success(account, _) = response else { fatalError() } switch response {
case .success(let account, _):
self.mastodonController.persistentContainer.addOrUpdate(account: account, incrementReferenceCount: true) { (account) in self.mastodonController.persistentContainer.addOrUpdate(account: account, incrementReferenceCount: true) { (account) in
DispatchQueue.main.async { DispatchQueue.main.async {
self.updateAccountUI() self.updateAccountUI()
} }
} }
case .failure(let error):
DispatchQueue.main.async {
let config = ToastConfiguration(from: error, with: "Loading", in: self) { [unowned self] (toast) in
toast.dismissToast(animated: true)
self.loadAccount()
}
self.showToast(configuration: config, animated: true)
}
}
} }
} }
} }
@ -271,3 +282,6 @@ extension ProfileViewController: TabbedPageViewController {
selectPage(at: currentIndex - 1, animated: true) selectPage(at: currentIndex - 1, animated: true)
} }
} }
extension ProfileViewController: ToastableViewController {
}