Add external web feed to status so that it can prompt receiving system to pull down new articles.
This commit is contained in:
parent
a8dcf3eeee
commit
6ec11119f8
|
@ -98,12 +98,12 @@ final class CloudKitAccountDelegate: AccountDelegate {
|
|||
return
|
||||
}
|
||||
|
||||
let starredArticleIDs = syncStatuses.filter({ $0.key == .starred && $0.flag == true }).map({ $0.articleID })
|
||||
account.fetchArticlesAsync(.articleIDs(Set(starredArticleIDs))) { result in
|
||||
let articleIDs = syncStatuses.map({ $0.articleID })
|
||||
account.fetchArticlesAsync(.articleIDs(Set(articleIDs))) { result in
|
||||
|
||||
func processWithArticles(_ starredArticles: Set<Article>) {
|
||||
func processWithArticles(_ articles: Set<Article>) {
|
||||
|
||||
self.articlesZone.sendArticleStatus(syncStatuses, starredArticles: starredArticles) { result in
|
||||
self.articlesZone.sendArticleStatus(syncStatuses, articles: articles) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
self.database.deleteSelectedForProcessing(syncStatuses.map({ $0.articleID }) )
|
||||
|
@ -119,8 +119,8 @@ final class CloudKitAccountDelegate: AccountDelegate {
|
|||
}
|
||||
|
||||
switch result {
|
||||
case .success(let starredArticles):
|
||||
processWithArticles(starredArticles)
|
||||
case .success(let articles):
|
||||
processWithArticles(articles)
|
||||
case .failure(let databaseError):
|
||||
completion(.failure(databaseError))
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ final class CloudKitArticlesZone: CloudKitZone {
|
|||
struct CloudKitArticleStatus {
|
||||
static let recordType = "ArticleStatus"
|
||||
struct Fields {
|
||||
static let webFeedExternalID = "webFeedExternalID"
|
||||
static let read = "read"
|
||||
static let starred = "starred"
|
||||
static let userDeleted = "userDeleted"
|
||||
|
@ -81,8 +82,11 @@ final class CloudKitArticlesZone: CloudKitZone {
|
|||
}
|
||||
}
|
||||
|
||||
func sendArticleStatus(_ syncStatuses: [SyncStatus], starredArticles: Set<Article>, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
var records = makeStatusRecords(syncStatuses)
|
||||
func sendArticleStatus(_ syncStatuses: [SyncStatus], articles: Set<Article>, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||
|
||||
var records = makeStatusRecords(syncStatuses, articles)
|
||||
|
||||
let starredArticles = articles.filter({ $0.status.starred == true })
|
||||
makeArticleRecordsIfNecessary(starredArticles) { result in
|
||||
switch result {
|
||||
case .success(let articleRecords):
|
||||
|
@ -92,11 +96,11 @@ final class CloudKitArticlesZone: CloudKitZone {
|
|||
case .success:
|
||||
completion(.success(()))
|
||||
case .failure(let error):
|
||||
self.handleSendArticleStatusError(error, syncStatuses: syncStatuses, starredArticles: starredArticles, completion: completion)
|
||||
self.handleSendArticleStatusError(error, syncStatuses: syncStatuses, starredArticles: articles, completion: completion)
|
||||
}
|
||||
}
|
||||
case .failure(let error):
|
||||
self.handleSendArticleStatusError(error, syncStatuses: syncStatuses, starredArticles: starredArticles, completion: completion)
|
||||
self.handleSendArticleStatusError(error, syncStatuses: syncStatuses, starredArticles: articles, completion: completion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +110,7 @@ final class CloudKitArticlesZone: CloudKitZone {
|
|||
self.createZoneRecord() { result in
|
||||
switch result {
|
||||
case .success:
|
||||
self.sendArticleStatus(syncStatuses, starredArticles: starredArticles, completion: completion)
|
||||
self.sendArticleStatus(syncStatuses, articles: starredArticles, completion: completion)
|
||||
case .failure(let error):
|
||||
completion(.failure(error))
|
||||
}
|
||||
|
@ -120,7 +124,13 @@ final class CloudKitArticlesZone: CloudKitZone {
|
|||
|
||||
private extension CloudKitArticlesZone {
|
||||
|
||||
func makeStatusRecords(_ syncStatuses: [SyncStatus]) -> [CKRecord] {
|
||||
func makeStatusRecords(_ syncStatuses: [SyncStatus], _ articles: Set<Article>) -> [CKRecord] {
|
||||
|
||||
var articleDict = [String: Article]()
|
||||
for article in articles {
|
||||
articleDict[article.articleID] = article
|
||||
}
|
||||
|
||||
var records = [String: CKRecord]()
|
||||
|
||||
for status in syncStatuses {
|
||||
|
@ -132,6 +142,10 @@ private extension CloudKitArticlesZone {
|
|||
records[status.articleID] = record
|
||||
}
|
||||
|
||||
if let webFeedExternalID = articleDict[status.articleID]?.webFeed?.externalID {
|
||||
record![CloudKitArticleStatus.Fields.webFeedExternalID] = webFeedExternalID
|
||||
}
|
||||
|
||||
switch status.key {
|
||||
case .read:
|
||||
record![CloudKitArticleStatus.Fields.read] = status.flag ? "1" : "0"
|
||||
|
|
|
@ -94,25 +94,28 @@ private extension CloudKitArticlesZoneDelegate {
|
|||
if newArticleStatusIDs.isEmpty {
|
||||
group.leave()
|
||||
} else {
|
||||
self.account?.fetchArticlesAsync(FetchType.articleIDs(newArticleStatusIDs)) { result in
|
||||
switch result {
|
||||
case .success(let articles):
|
||||
|
||||
if articles.isEmpty {
|
||||
group.leave()
|
||||
} else {
|
||||
let webFeeds = Set(articles.compactMap({ $0.webFeed }))
|
||||
webFeeds.forEach { $0.dropConditionalGetInfo() }
|
||||
self.refreshProgress?.addToNumberOfTasksAndRemaining(webFeeds.count)
|
||||
self.refresher?.refreshFeeds(webFeeds) {
|
||||
group.leave()
|
||||
}
|
||||
}
|
||||
|
||||
case .failure:
|
||||
group.leave()
|
||||
|
||||
var webFeedExternalIDDict = [String: String]()
|
||||
for record in records {
|
||||
if let webFeedExternalID = record[CloudKitArticlesZone.CloudKitArticleStatus.Fields.webFeedExternalID] as? String {
|
||||
webFeedExternalIDDict[record.externalID] = webFeedExternalID
|
||||
}
|
||||
}
|
||||
|
||||
var webFeeds = Set<WebFeed>()
|
||||
for newArticleStatusID in newArticleStatusIDs {
|
||||
if let webFeedExternalID = webFeedExternalIDDict[newArticleStatusID],
|
||||
let webFeed = self.account?.existingWebFeed(withExternalID: webFeedExternalID) {
|
||||
webFeeds.insert(webFeed)
|
||||
}
|
||||
}
|
||||
|
||||
webFeeds.forEach { $0.dropConditionalGetInfo() }
|
||||
self.refreshProgress?.addToNumberOfTasksAndRemaining(webFeeds.count)
|
||||
self.refresher?.refreshFeeds(webFeeds) {
|
||||
group.leave()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case .failure:
|
||||
|
|
Loading…
Reference in New Issue