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

View File

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