Fix TimelineTableVC item hash including status state

Fixes crash when refreshing on iOS 14
This commit is contained in:
Shadowfacts 2021-06-27 15:09:10 -04:00
parent f8b79ef34f
commit 1e7a6af0bf
1 changed files with 24 additions and 3 deletions

View File

@ -177,11 +177,11 @@ class TimelineTableViewController: DiffableTimelineLikeTableViewController<Timel
self.mastodonController.persistentContainer.addAll(statuses: statuses) {
var snapshot = currentSnapshot
let identifiers = statuses.map { Item.status(id: $0.id, state: .unknown) }
let newIdentifiers = statuses.map { Item.status(id: $0.id, state: .unknown) }
if let first = snapshot.itemIdentifiers(inSection: .statuses).first {
snapshot.insertItems(identifiers, beforeItem: first)
snapshot.insertItems(newIdentifiers, beforeItem: first)
} else {
snapshot.appendItems(identifiers, toSection: .statuses)
snapshot.appendItems(newIdentifiers, toSection: .statuses)
}
completion(.success(snapshot))
}
@ -205,6 +205,27 @@ extension TimelineTableViewController {
enum Item: Hashable {
case status(id: String, state: StatusState)
case confirmLoadMore
static func ==(lhs: Item, rhs: Item) -> Bool {
switch (lhs, rhs) {
case let (.status(id: a, state: _), .status(id: b, state: _)):
return a == b
case (.confirmLoadMore, .confirmLoadMore):
return true
default:
return false
}
}
func hash(into hasher: inout Hasher) {
switch self {
case let .status(id: id, state: _):
hasher.combine(0)
hasher.combine(id)
case .confirmLoadMore:
hasher.combine(1)
}
}
}
}