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