Implement sinceID usage when loading latest posts (IOS-266)

This commit is contained in:
Marcus Kida 2024-05-02 11:25:22 +02:00
parent 9714a37386
commit efcb91fff1
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
2 changed files with 12 additions and 3 deletions

View File

@ -116,15 +116,20 @@ extension HomeTimelineViewModel.LoadLatestState {
do {
await AuthenticationServiceProvider.shared.fetchAccounts(apiService: viewModel.context.apiService)
let response: Mastodon.Response.Content<[Mastodon.Entity.Status]>
/// To find out wether or not we need to show the "Load More" button
/// we have make sure to eventually overlap with the most recent cached item
let sinceID = latestFeedRecords.count > 1 ? latestFeedRecords[1].id : "1"
switch viewModel.timelineContext {
case .home:
response = try await viewModel.context.apiService.homeTimeline(
sinceID: sinceID,
authenticationBox: viewModel.authContext.mastodonAuthenticationBox
)
case .public:
response = try await viewModel.context.apiService.publicTimeline(
query: .init(local: true),
query: .init(local: true, sinceID: sinceID),
authenticationBox: viewModel.authContext.mastodonAuthenticationBox
)
}
@ -149,6 +154,8 @@ extension HomeTimelineViewModel.LoadLatestState {
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)

View File

@ -79,7 +79,8 @@ extension MastodonFeed: Hashable {
lhs.status?.poll == rhs.status?.poll &&
lhs.status?.reblog?.poll == rhs.status?.reblog?.poll &&
lhs.status?.poll?.entity == rhs.status?.poll?.entity &&
lhs.status?.reblog?.poll?.entity == rhs.status?.reblog?.poll?.entity
lhs.status?.reblog?.poll?.entity == rhs.status?.reblog?.poll?.entity &&
lhs.isLoadingMore == rhs.isLoadingMore
}
public func hash(into hasher: inout Hasher) {
@ -94,6 +95,7 @@ extension MastodonFeed: Hashable {
hasher.combine(status?.reblog?.poll)
hasher.combine(status?.poll?.entity)
hasher.combine(status?.reblog?.poll?.entity)
hasher.combine(isLoadingMore)
}
}