Fix potential excessive Load More at end of timeline (IOS-275)

This commit is contained in:
Marcus Kida 2024-06-19 13:54:58 +02:00
parent a23b5089d0
commit d61b10a8e6
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
1 changed files with 6 additions and 1 deletions

View File

@ -147,10 +147,15 @@ extension HomeTimelineViewModel.LoadLatestState {
let last = statuses.last
if let latestFirstId = latestFeedRecords.first?.id, let last, last.id == latestFirstId {
/// We have an overlap with the existing Statuses, thus no _Load More_ required
toAdd = statuses.prefix(statuses.count-1).map({ MastodonFeed.fromStatus($0.asMastodonStatus, kind: .home) })
} else {
} else if latestFeedRecords.isNotEmpty {
/// Our fetched Statuses do **not** overlap with the existing ones, we need a _Load More_ Button
toAdd = statuses.map({ MastodonFeed.fromStatus($0.asMastodonStatus, kind: .home) })
toAdd.last?.hasMore = true
} else {
/// We do not have existing items, no load more is required as there can't be a gap
toAdd = statuses.map({ MastodonFeed.fromStatus($0.asMastodonStatus, kind: .home) })
}
viewModel.dataController.records = (toAdd + latestFeedRecords).removingDuplicates()