Simplify code (IOS-275)

This commit is contained in:
Marcus Kida 2024-06-19 13:57:56 +02:00
parent a05fc48683
commit 63fc0488e4
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
1 changed files with 3 additions and 5 deletions

View File

@ -149,13 +149,11 @@ extension HomeTimelineViewModel.LoadLatestState {
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 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 is no gap
/// If we do not have existing items, no _Load More_ is required as there is no gap
/// If 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 = latestFeedRecords.isNotEmpty
}
viewModel.dataController.records = (toAdd + latestFeedRecords).removingDuplicates()