Fix crash when showing profile for uncached account
This commit is contained in:
parent
29aed65b99
commit
eef9b96a1a
|
@ -25,7 +25,7 @@ class ProfileStatusesViewController: EnhancedTableViewController {
|
||||||
private var older: RequestRange?
|
private var older: RequestRange?
|
||||||
private var newer: RequestRange?
|
private var newer: RequestRange?
|
||||||
|
|
||||||
private var loaded = false
|
var loaded = false
|
||||||
|
|
||||||
init(accountID: String?, kind: Kind, mastodonController: MastodonController) {
|
init(accountID: String?, kind: Kind, mastodonController: MastodonController) {
|
||||||
self.accountID = accountID
|
self.accountID = accountID
|
||||||
|
@ -61,12 +61,14 @@ class ProfileStatusesViewController: EnhancedTableViewController {
|
||||||
if !loaded,
|
if !loaded,
|
||||||
let accountID = accountID,
|
let accountID = accountID,
|
||||||
let account = mastodonController.persistentContainer.account(for: accountID) {
|
let account = mastodonController.persistentContainer.account(for: accountID) {
|
||||||
loaded = true
|
|
||||||
updateUI(account: account)
|
updateUI(account: account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateUI(account: AccountMO) {
|
func updateUI(account: AccountMO) {
|
||||||
|
guard !loaded else { return }
|
||||||
|
loaded = true
|
||||||
|
|
||||||
if kind == .statuses {
|
if kind == .statuses {
|
||||||
getPinnedStatuses { (response) in
|
getPinnedStatuses { (response) in
|
||||||
guard case let .success(statuses, _) = response else {
|
guard case let .success(statuses, _) = response else {
|
||||||
|
|
|
@ -49,6 +49,10 @@ class ProfileViewController: UIPageViewController {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
mastodonController.persistentContainer.account(for: accountID)?.decrementReferenceCount()
|
||||||
|
}
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
@ -56,7 +60,6 @@ class ProfileViewController: UIPageViewController {
|
||||||
|
|
||||||
headerView = ProfileHeaderView.create()
|
headerView = ProfileHeaderView.create()
|
||||||
headerView.delegate = self
|
headerView.delegate = self
|
||||||
headerView.updateUI(for: accountID)
|
|
||||||
|
|
||||||
selectPage(at: 0, animated: false)
|
selectPage(at: 0, animated: false)
|
||||||
|
|
||||||
|
@ -70,6 +73,24 @@ class ProfileViewController: UIPageViewController {
|
||||||
.filter { [weak self] in $0 == self?.accountID }
|
.filter { [weak self] in $0 == self?.accountID }
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { [weak self] (_) in self?.updateAccountUI() }
|
.sink { [weak self] (_) in self?.updateAccountUI() }
|
||||||
|
|
||||||
|
if mastodonController.persistentContainer.account(for: accountID) != nil {
|
||||||
|
headerView.updateUI(for: accountID)
|
||||||
|
} else {
|
||||||
|
let req = Client.getAccount(id: accountID)
|
||||||
|
mastodonController.run(req) { [weak self] (response) in
|
||||||
|
guard let self = self else { return }
|
||||||
|
guard case let .success(account, _) = response else { fatalError() }
|
||||||
|
self.mastodonController.persistentContainer.addOrUpdate(account: account, incrementReferenceCount: true) { (account) in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.headerView.updateUI(for: self.accountID)
|
||||||
|
self.pageControllers.forEach {
|
||||||
|
$0.updateUI(account: account)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func updateAccountUI() {
|
private func updateAccountUI() {
|
||||||
|
|
Loading…
Reference in New Issue