diff --git a/IceCubesAppWidgetsExtension/Shared/SharedUtils.swift b/IceCubesAppWidgetsExtension/Shared/SharedUtils.swift index b8c76f44..0e3c7a82 100644 --- a/IceCubesAppWidgetsExtension/Shared/SharedUtils.swift +++ b/IceCubesAppWidgetsExtension/Shared/SharedUtils.swift @@ -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: diff --git a/Packages/Network/Sources/Network/Endpoint/Timelines.swift b/Packages/Network/Sources/Network/Endpoint/Timelines.swift index 2749b827..c709b6b4 100644 --- a/Packages/Network/Sources/Network/Endpoint/Timelines.swift +++ b/Packages/Network/Sources/Network/Endpoint/Timelines.swift @@ -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): diff --git a/Packages/Timeline/Sources/Timeline/TimelineFilter.swift b/Packages/Timeline/Sources/Timeline/TimelineFilter.swift index 2fa739e6..815c8c9c 100644 --- a/Packages/Timeline/Sources/Timeline/TimelineFilter.swift +++ b/Packages/Timeline/Sources/Timeline/TimelineFilter.swift @@ -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) diff --git a/Packages/Timeline/Sources/Timeline/actors/TimelineStatusFetcher.swift b/Packages/Timeline/Sources/Timeline/actors/TimelineStatusFetcher.swift index 91a2cac2..35b8bc99 100644 --- a/Packages/Timeline/Sources/Timeline/actors/TimelineStatusFetcher.swift +++ b/Packages/Timeline/Sources/Timeline/actors/TimelineStatusFetcher.swift @@ -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)) } }