Implement since id as a parameter to limit the number returned

This commit is contained in:
Maurice Parker 2020-05-02 08:12:05 -05:00
parent a522ec67b3
commit 55eea27c8d
3 changed files with 27 additions and 2 deletions

View File

@ -177,6 +177,10 @@ public struct TwitterFeedProvider: FeedProvider {
var parameters = [String: Any]()
var isSearch = false
if let sinceToken = webFeed.sinceToken, let sinceID = Int(sinceToken) {
parameters["since_id"] = sinceID
}
switch urlComponents.path {
case "", "/", "/home":
parameters["count"] = 100
@ -208,8 +212,11 @@ public struct TwitterFeedProvider: FeedProvider {
retrieveTweets(api: api, parameters: parameters, isSearch: isSearch) { result in
switch result {
case .success(let tweets):
let parsedItems = self.makeParsedItems(webFeed.url, tweets)
case .success(let statuses):
if let sinceID = statuses.first?.idStr {
webFeed.sinceToken = sinceID
}
let parsedItems = self.makeParsedItems(webFeed.url, statuses)
completion(.success(parsedItems))
case .failure(let error):
completion(.failure(error))

View File

@ -153,6 +153,15 @@ public final class WebFeed: Feed, Renamable, Hashable {
}
}
public var sinceToken: String? {
get {
return metadata.sinceToken
}
set {
metadata.sinceToken = newValue
}
}
public var externalID: String? {
get {
return metadata.externalID

View File

@ -27,6 +27,7 @@ final class WebFeedMetadata: Codable {
case isNotifyAboutNewArticles
case isArticleExtractorAlwaysOn
case conditionalGetInfo
case sinceToken
case externalID = "subscriptionID"
case folderRelationship
}
@ -111,6 +112,14 @@ final class WebFeedMetadata: Codable {
}
}
var sinceToken: String? {
didSet {
if externalID != oldValue {
valueDidChange(.externalID)
}
}
}
var externalID: String? {
didSet {
if externalID != oldValue {