DRY up feed id code
only the filter really changes
This commit is contained in:
parent
86541d4e32
commit
a66759a065
@ -189,32 +189,21 @@ final class FeedWranglerAPICaller: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func retrieveUnreadFeedItemIds(page: Int = 0, completion: @escaping (Result<[FeedWranglerFeedItemId], Error>) -> Void) {
|
|
||||||
let url = FeedWranglerConfig.clientURL
|
|
||||||
.appendingPathComponent("feed_items/list_ids")
|
|
||||||
.appendingQueryItems([
|
|
||||||
URLQueryItem(name: "read", value: "false"),
|
|
||||||
URLQueryItem(name: "offset", value: String(page * FeedWranglerConfig.idsPageSize)),
|
|
||||||
])
|
|
||||||
|
|
||||||
standardSend(url: url, resultType: FeedWranglerFeedItemIdsRequest.self) { result in
|
func retrieveUnreadFeedItemIds(completion: @escaping (Result<[FeedWranglerFeedItemId], Error>) -> Void) {
|
||||||
switch result {
|
retrieveAllFeedItemIds(filters: [URLQueryItem(name: "read", value: "false")], completion: completion)
|
||||||
case .success(let (_, results)):
|
|
||||||
completion(.success(results?.feedItems ?? []))
|
|
||||||
|
|
||||||
case .failure(let error):
|
|
||||||
completion(.failure(error))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func retrieveAllUnreadFeedItemIds(foundItems: [FeedWranglerFeedItemId] = [], page: Int = 0, completion: @escaping (Result<[FeedWranglerFeedItemId], Error>) -> Void) {
|
func retrieveStarredFeedItemIds(completion: @escaping (Result<[FeedWranglerFeedItemId], Error>) -> Void) {
|
||||||
retrieveUnreadFeedItemIds(page: page) { result in
|
retrieveAllFeedItemIds(filters: [URLQueryItem(name: "starred", value: "true")], completion: completion)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func retrieveAllFeedItemIds(filters: [URLQueryItem] = [], foundItems: [FeedWranglerFeedItemId] = [], page: Int = 0, completion: @escaping (Result<[FeedWranglerFeedItemId], Error>) -> Void) {
|
||||||
|
retrieveFeedItemIds(filters: filters, page: page) { result in
|
||||||
switch result {
|
switch result {
|
||||||
case .success(let newItems):
|
case .success(let newItems):
|
||||||
if newItems.count > 0 {
|
if newItems.count > 0 {
|
||||||
self.retrieveAllUnreadFeedItemIds(foundItems: foundItems + newItems, page: (page + 1), completion: completion)
|
self.retrieveAllFeedItemIds(filters: filters, foundItems: foundItems + newItems, page: (page + 1), completion: completion)
|
||||||
} else {
|
} else {
|
||||||
completion(.success(foundItems + newItems))
|
completion(.success(foundItems + newItems))
|
||||||
}
|
}
|
||||||
@ -225,13 +214,10 @@ final class FeedWranglerAPICaller: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func retrieveStarredFeedItemIds(page: Int = 0, completion: @escaping (Result<[FeedWranglerFeedItemId], Error>) -> Void) {
|
private func retrieveFeedItemIds(filters: [URLQueryItem] = [], page: Int = 0, completion: @escaping (Result<[FeedWranglerFeedItemId], Error>) -> Void) {
|
||||||
let url = FeedWranglerConfig.clientURL
|
let url = FeedWranglerConfig.clientURL
|
||||||
.appendingPathComponent("feed_items/list_ids")
|
.appendingPathComponent("feed_items/list_ids")
|
||||||
.appendingQueryItems([
|
.appendingQueryItems(filters + [URLQueryItem(name: "offset", value: String(page * FeedWranglerConfig.idsPageSize))])
|
||||||
URLQueryItem(name: "starred", value: "true"),
|
|
||||||
URLQueryItem(name: "offset", value: String(page * FeedWranglerConfig.idsPageSize)),
|
|
||||||
])
|
|
||||||
|
|
||||||
standardSend(url: url, resultType: FeedWranglerFeedItemIdsRequest.self) { result in
|
standardSend(url: url, resultType: FeedWranglerFeedItemIdsRequest.self) { result in
|
||||||
switch result {
|
switch result {
|
||||||
@ -243,22 +229,6 @@ final class FeedWranglerAPICaller: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func retrieveAllStarredFeedItemIds(foundItems: [FeedWranglerFeedItemId] = [], page: Int = 0, completion: @escaping (Result<[FeedWranglerFeedItemId], Error>) -> Void) {
|
|
||||||
retrieveStarredFeedItemIds(page: page) { result in
|
|
||||||
switch result {
|
|
||||||
case .success(let newItems):
|
|
||||||
if newItems.count > 0 {
|
|
||||||
self.retrieveAllStarredFeedItemIds(foundItems: foundItems + newItems, page: (page + 1), completion: completion)
|
|
||||||
} else {
|
|
||||||
completion(.success(foundItems + newItems))
|
|
||||||
}
|
|
||||||
|
|
||||||
case .failure(let error):
|
|
||||||
completion(.failure(error))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateArticleStatus(_ articleID: String, _ statuses: [SyncStatus], completion: @escaping () -> Void) {
|
func updateArticleStatus(_ articleID: String, _ statuses: [SyncStatus], completion: @escaping () -> Void) {
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ final class FeedWranglerAccountDelegate: AccountDelegate {
|
|||||||
let group = DispatchGroup()
|
let group = DispatchGroup()
|
||||||
|
|
||||||
group.enter()
|
group.enter()
|
||||||
caller.retrieveAllUnreadFeedItemIds { result in
|
caller.retrieveUnreadFeedItemIds { result in
|
||||||
switch result {
|
switch result {
|
||||||
case .success(let items):
|
case .success(let items):
|
||||||
self.syncArticleReadState(account, items)
|
self.syncArticleReadState(account, items)
|
||||||
@ -263,7 +263,7 @@ final class FeedWranglerAccountDelegate: AccountDelegate {
|
|||||||
|
|
||||||
// starred
|
// starred
|
||||||
group.enter()
|
group.enter()
|
||||||
caller.retrieveAllStarredFeedItemIds { result in
|
caller.retrieveStarredFeedItemIds { result in
|
||||||
switch result {
|
switch result {
|
||||||
case .success(let items):
|
case .success(let items):
|
||||||
self.syncArticleStarredState(account, items)
|
self.syncArticleStarredState(account, items)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user