Improve load more (IOS-266)
This commit is contained in:
parent
7b5b0dacc7
commit
d9a7bbe00d
|
@ -147,18 +147,20 @@ extension HomeTimelineViewModel.LoadLatestState {
|
|||
viewModel.dataController.records = {
|
||||
var oldRecords = viewModel.dataController.records
|
||||
|
||||
var newRecords: [MastodonFeed] = newStatuses.map { status in
|
||||
let hasMore: Bool = {
|
||||
guard
|
||||
let firstOldStatus = oldRecords.first?.status
|
||||
else {
|
||||
return false
|
||||
}
|
||||
/// if the most recent cached item overlaps with the last returned status we know that there
|
||||
/// is no gap in the timline
|
||||
return status == newStatuses.last && status != firstOldStatus.entity
|
||||
}()
|
||||
return MastodonFeed.fromStatus(.fromEntity(status), kind: .home, hasMore: hasMore)
|
||||
var newRecords = [MastodonFeed]()
|
||||
for (index, status) in newStatuses.enumerated() {
|
||||
if index < newStatuses.count - 1 {
|
||||
newRecords.append(
|
||||
MastodonFeed.fromStatus(.fromEntity(status), kind: .home, hasMore: false)
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
||||
let hasMore = status != oldRecords.first?.status?.entity
|
||||
|
||||
newRecords.append(
|
||||
MastodonFeed.fromStatus(.fromEntity(status), kind: .home, hasMore: hasMore)
|
||||
)
|
||||
}
|
||||
for (i, record) in newRecords.enumerated() {
|
||||
if let index = oldRecords.firstIndex(where: { $0.status?.reblog?.id == record.id || $0.status?.id == record.id }) {
|
||||
|
|
|
@ -149,7 +149,6 @@ extension HomeTimelineViewModel {
|
|||
@MainActor
|
||||
func loadMore(item: StatusItem, indexPath: IndexPath) async {
|
||||
guard case let .feedLoader(record) = item else { return }
|
||||
guard let diffableDataSource = diffableDataSource else { return }
|
||||
|
||||
guard let status = record.status else { return }
|
||||
record.isLoadingMore = true
|
||||
|
@ -158,7 +157,7 @@ extension HomeTimelineViewModel {
|
|||
|
||||
// fetch data
|
||||
let response = try? await context.apiService.homeTimeline(
|
||||
maxID: status.id,
|
||||
sinceID: status.id,
|
||||
authenticationBox: authContext.mastodonAuthenticationBox
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue