Fix crash when user refreshes profile before initial pinned statuses request completes

This commit is contained in:
Shadowfacts 2021-01-12 22:17:01 -05:00
parent 678ed4959b
commit 69c2faf0e1
1 changed files with 2 additions and 1 deletions

View File

@ -182,7 +182,8 @@ class ProfileStatusesViewController: TimelineLikeTableViewController<TimelineEnt
} }
self.mastodonController.persistentContainer.addAll(statuses: newPinnedStatues) { self.mastodonController.persistentContainer.addAll(statuses: newPinnedStatues) {
let oldPinnedStatuses = self.sections[0] // if the user refreshes before the initial pinned statuses request completes, self.sections will be empty
let oldPinnedStatuses = self.sections.isEmpty ? [] : self.sections[0]
let pinnedStatues = newPinnedStatues.map { (status) -> TimelineEntry in let pinnedStatues = newPinnedStatues.map { (status) -> TimelineEntry in
let state: StatusState let state: StatusState
if let (_, oldState) = oldPinnedStatuses.first(where: { $0.id == status.id }) { if let (_, oldState) = oldPinnedStatuses.first(where: { $0.id == status.id }) {