Fix crash when showing trending hashtag with less than two days of history

This commit is contained in:
Shadowfacts 2023-11-10 14:04:11 -05:00
parent cb47443649
commit 676e603ffc
1 changed files with 2 additions and 1 deletions

View File

@ -67,7 +67,8 @@ class TrendingHashtagCollectionViewCell: UICollectionViewCell {
historyView.setHistory(hashtag.history)
historyView.isHidden = hashtag.history == nil || hashtag.history!.count < 2
if let history = hashtag.history {
if let history = hashtag.history,
history.count >= 2 {
let sorted = history.sorted(by: { $0.day < $1.day })
let lastTwo = sorted[(sorted.count - 2)...]
let accounts = lastTwo.map(\.accounts).reduce(0, +)