mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-22 00:11:00 +00:00
Fetch timeline 40 per page + 200 per batch
This commit is contained in:
parent
9ec6a4ef66
commit
d2eca1d646
4 changed files with 32 additions and 17 deletions
|
@ -16,7 +16,8 @@ func loadStatuses(for timeline: TimelineFilter,
|
|||
var statuses: [Status] = try await client.get(endpoint: timeline.endpoint(sinceId: nil,
|
||||
maxId: nil,
|
||||
minId: nil,
|
||||
offset: nil))
|
||||
offset: nil,
|
||||
limit: 6))
|
||||
statuses = statuses.filter { $0.reblog == nil && !$0.content.asRawText.isEmpty }
|
||||
switch widgetFamily {
|
||||
case .systemSmall, .systemMedium:
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import Foundation
|
||||
|
||||
public enum Timelines: Endpoint {
|
||||
case pub(sinceId: String?, maxId: String?, minId: String?, local: Bool)
|
||||
case home(sinceId: String?, maxId: String?, minId: String?)
|
||||
case pub(sinceId: String?, maxId: String?, minId: String?, local: Bool, limit: Int?)
|
||||
case home(sinceId: String?, maxId: String?, minId: String?, limit: Int?)
|
||||
case list(listId: String, sinceId: String?, maxId: String?, minId: String?)
|
||||
case hashtag(tag: String, additional: [String]?, maxId: String?, minId: String?)
|
||||
case link(url: URL, sinceId: String?, maxId: String?, minId: String?)
|
||||
|
@ -24,12 +24,19 @@ public enum Timelines: Endpoint {
|
|||
|
||||
public func queryItems() -> [URLQueryItem]? {
|
||||
switch self {
|
||||
case let .pub(sinceId, maxId, minId, local):
|
||||
case let .pub(sinceId, maxId, minId, local, limit):
|
||||
var params = makePaginationParam(sinceId: sinceId, maxId: maxId, mindId: minId) ?? []
|
||||
params.append(.init(name: "local", value: local ? "true" : "false"))
|
||||
if let limit {
|
||||
params.append(.init(name: "limit", value: String(limit)))
|
||||
}
|
||||
return params
|
||||
case let .home(sinceId, maxId, mindId, limit):
|
||||
var params = makePaginationParam(sinceId: sinceId, maxId: maxId, mindId: mindId) ?? []
|
||||
if let limit {
|
||||
params.append(.init(name: "limit", value: String(limit)))
|
||||
}
|
||||
return params
|
||||
case let .home(sinceId, maxId, mindId):
|
||||
return makePaginationParam(sinceId: sinceId, maxId: maxId, mindId: mindId)
|
||||
case let .list(_, sinceId, maxId, mindId):
|
||||
return makePaginationParam(sinceId: sinceId, maxId: maxId, mindId: mindId)
|
||||
case let .hashtag(_, additional, maxId, minId):
|
||||
|
|
|
@ -157,22 +157,26 @@ public enum TimelineFilter: Hashable, Equatable, Identifiable, Sendable {
|
|||
}
|
||||
}
|
||||
|
||||
public func endpoint(sinceId: String?, maxId: String?, minId: String?, offset: Int?) -> Endpoint {
|
||||
public func endpoint(sinceId: String?,
|
||||
maxId: String?,
|
||||
minId: String?,
|
||||
offset: Int?,
|
||||
limit: Int?) -> Endpoint {
|
||||
switch self {
|
||||
case .federated: return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: false)
|
||||
case .local: return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: true)
|
||||
case .federated: return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: false, limit: limit)
|
||||
case .local: return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: true, limit: limit)
|
||||
case let .remoteLocal(_, filter):
|
||||
switch filter {
|
||||
case .local:
|
||||
return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: true)
|
||||
return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: true, limit: limit)
|
||||
case .federated:
|
||||
return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: false)
|
||||
return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: false, limit: limit)
|
||||
case .trending:
|
||||
return Trends.statuses(offset: offset)
|
||||
}
|
||||
case .latest: return Timelines.home(sinceId: nil, maxId: nil, minId: nil)
|
||||
case .resume: return Timelines.home(sinceId: nil, maxId: nil, minId: nil)
|
||||
case .home: return Timelines.home(sinceId: sinceId, maxId: maxId, minId: minId)
|
||||
case .latest: return Timelines.home(sinceId: nil, maxId: nil, minId: nil, limit: limit)
|
||||
case .resume: return Timelines.home(sinceId: nil, maxId: nil, minId: nil, limit: limit)
|
||||
case .home: return Timelines.home(sinceId: sinceId, maxId: maxId, minId: minId, limit: limit)
|
||||
case .trending: return Trends.statuses(offset: offset)
|
||||
case let .link(url, _): return Timelines.link(url: url, sinceId: sinceId, maxId: maxId, minId: minId)
|
||||
case let .list(list): return Timelines.list(listId: list.id, sinceId: sinceId, maxId: maxId, minId: minId)
|
||||
|
|
|
@ -25,7 +25,8 @@ struct TimelineStatusFetcher: TimelineStatusFetching {
|
|||
return try await client.get(endpoint: timeline.endpoint(sinceId: nil,
|
||||
maxId: nil,
|
||||
minId: nil,
|
||||
offset: 0))
|
||||
offset: 0,
|
||||
limit: 40))
|
||||
}
|
||||
|
||||
func fetchNewPages(client: Client?, timeline: TimelineFilter, minId: String, maxPages: Int) async throws -> [Status] {
|
||||
|
@ -39,7 +40,8 @@ struct TimelineStatusFetcher: TimelineStatusFetching {
|
|||
sinceId: nil,
|
||||
maxId: nil,
|
||||
minId: latestMinId,
|
||||
offset: nil
|
||||
offset: nil,
|
||||
limit: 40
|
||||
))
|
||||
|
||||
if newStatuses.isEmpty { break }
|
||||
|
@ -55,6 +57,7 @@ struct TimelineStatusFetcher: TimelineStatusFetching {
|
|||
return try await client.get(endpoint: timeline.endpoint(sinceId: nil,
|
||||
maxId: lastId,
|
||||
minId: nil,
|
||||
offset: offset))
|
||||
offset: offset,
|
||||
limit: 40))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue