forked from shadowfacts/Tusker
Load timeline posts in pages of 40
This commit is contained in:
parent
9d7c876e3c
commit
d8901b38f5
|
@ -947,8 +947,11 @@ extension TimelineViewController {
|
|||
extension TimelineViewController {
|
||||
typealias TimelineItem = String // status ID
|
||||
|
||||
// the maximum mastodon will provide in a single request
|
||||
private static let pageSize = 40
|
||||
|
||||
func loadInitial() async throws -> [TimelineItem] {
|
||||
let request = Client.getStatuses(timeline: timeline)
|
||||
let request = Client.getStatuses(timeline: timeline, range: .count(TimelineViewController.pageSize))
|
||||
let (statuses, _) = try await mastodonController.run(request)
|
||||
|
||||
await withCheckedContinuation { continuation in
|
||||
|
@ -965,7 +968,7 @@ extension TimelineViewController {
|
|||
guard case .status(id: let id, _, _) = dataSource.itemIdentifier(for: IndexPath(row: 0, section: statusesSection)) else {
|
||||
throw Error.noNewer
|
||||
}
|
||||
let newer = RequestRange.after(id: id, count: nil)
|
||||
let newer = RequestRange.after(id: id, count: TimelineViewController.pageSize)
|
||||
|
||||
let request = Client.getStatuses(timeline: timeline, range: newer)
|
||||
let (statuses, _) = try await mastodonController.run(request)
|
||||
|
@ -989,7 +992,7 @@ extension TimelineViewController {
|
|||
guard case .status(id: let id, _, _) = dataSource.itemIdentifier(for: IndexPath(row: snapshot.numberOfItems(inSection: .statuses) - 1, section: statusesSection)) else {
|
||||
throw Error.noNewer
|
||||
}
|
||||
let older = RequestRange.before(id: id, count: nil)
|
||||
let older = RequestRange.before(id: id, count: TimelineViewController.pageSize)
|
||||
|
||||
let request = Client.getStatuses(timeline: timeline, range: older)
|
||||
let (statuses, _) = try await mastodonController.run(request)
|
||||
|
@ -1020,13 +1023,13 @@ extension TimelineViewController {
|
|||
// not really the right error but w/e
|
||||
throw Error.noGap
|
||||
}
|
||||
range = .before(id: id, count: nil)
|
||||
range = .before(id: id, count: TimelineViewController.pageSize)
|
||||
case .below:
|
||||
guard gapIndexPath.row < statusItemsCount - 1,
|
||||
case .status(id: let id, _, _) = dataSource.itemIdentifier(for: IndexPath(row: gapIndexPath.row + 1, section: gapIndexPath.section)) else {
|
||||
throw Error.noGap
|
||||
}
|
||||
range = .after(id: id, count: nil)
|
||||
range = .after(id: id, count: TimelineViewController.pageSize)
|
||||
}
|
||||
|
||||
let request = Client.getStatuses(timeline: timeline, range: range)
|
||||
|
|
Loading…
Reference in New Issue