Merge branch 'master' into accent-color-experimental
This commit is contained in:
commit
bbbeaba46c
|
@ -594,18 +594,7 @@ private extension CloudKitAccountDelegate {
|
||||||
self.refreshProgress.completeTask()
|
self.refreshProgress.completeTask()
|
||||||
|
|
||||||
self.refresher.refreshFeeds(webFeeds) {
|
self.refresher.refreshFeeds(webFeeds) {
|
||||||
|
|
||||||
account.metadata.lastArticleFetchEndTime = Date()
|
account.metadata.lastArticleFetchEndTime = Date()
|
||||||
|
|
||||||
self.sendArticleStatus(for: account) { result in
|
|
||||||
switch result {
|
|
||||||
case .success:
|
|
||||||
completion(.success(()))
|
|
||||||
case .failure(let error):
|
|
||||||
fail(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
|
@ -638,12 +627,13 @@ private extension CloudKitAccountDelegate {
|
||||||
|
|
||||||
extension CloudKitAccountDelegate: LocalAccountRefresherDelegate {
|
extension CloudKitAccountDelegate: LocalAccountRefresherDelegate {
|
||||||
|
|
||||||
func localAccountRefresher(_ refresher: LocalAccountRefresher, didProcess newAndUpdatedArticles: NewAndUpdatedArticles) {
|
func localAccountRefresher(_ refresher: LocalAccountRefresher, didProcess newAndUpdatedArticles: NewAndUpdatedArticles, completion: @escaping () -> Void) {
|
||||||
if let newArticles = newAndUpdatedArticles.newArticles {
|
if let newArticles = newAndUpdatedArticles.newArticles {
|
||||||
let syncStatuses = newArticles.map { article in
|
articlesZone.sendNewArticles(newArticles) { _ in
|
||||||
return SyncStatus(articleID: article.articleID, key: .read, flag: false)
|
completion()
|
||||||
}
|
}
|
||||||
database.insertStatuses(syncStatuses)
|
} else {
|
||||||
|
completion()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,6 @@ final class CloudKitArticlesZone: CloudKitZone {
|
||||||
static let webFeedExternalID = "webFeedExternalID"
|
static let webFeedExternalID = "webFeedExternalID"
|
||||||
static let read = "read"
|
static let read = "read"
|
||||||
static let starred = "starred"
|
static let starred = "starred"
|
||||||
static let userDeleted = "userDeleted"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +81,11 @@ final class CloudKitArticlesZone: CloudKitZone {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sendNewArticles(_ articles: Set<Article>, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||||
|
let records = makeNewStatusRecords(articles)
|
||||||
|
saveIfNew(records, completion: completion)
|
||||||
|
}
|
||||||
|
|
||||||
func sendArticleStatus(_ syncStatuses: [SyncStatus], articles: Set<Article>, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
func sendArticleStatus(_ syncStatuses: [SyncStatus], articles: Set<Article>, completion: @escaping ((Result<Void, Error>) -> Void)) {
|
||||||
|
|
||||||
var records = makeStatusRecords(syncStatuses, articles)
|
var records = makeStatusRecords(syncStatuses, articles)
|
||||||
|
@ -124,6 +128,23 @@ final class CloudKitArticlesZone: CloudKitZone {
|
||||||
|
|
||||||
private extension CloudKitArticlesZone {
|
private extension CloudKitArticlesZone {
|
||||||
|
|
||||||
|
func makeNewStatusRecords(_ articles: Set<Article>) -> [CKRecord] {
|
||||||
|
|
||||||
|
var records = [CKRecord]()
|
||||||
|
|
||||||
|
for article in articles {
|
||||||
|
let recordID = CKRecord.ID(recordName: article.articleID, zoneID: Self.zoneID)
|
||||||
|
let record = CKRecord(recordType: CloudKitArticleStatus.recordType, recordID: recordID)
|
||||||
|
if let webFeedExternalID = article.webFeed?.externalID {
|
||||||
|
record[CloudKitArticleStatus.Fields.webFeedExternalID] = webFeedExternalID
|
||||||
|
}
|
||||||
|
record[CloudKitArticleStatus.Fields.read] = "0"
|
||||||
|
records.append(record)
|
||||||
|
}
|
||||||
|
|
||||||
|
return records
|
||||||
|
}
|
||||||
|
|
||||||
func makeStatusRecords(_ syncStatuses: [SyncStatus], _ articles: Set<Article>) -> [CKRecord] {
|
func makeStatusRecords(_ syncStatuses: [SyncStatus], _ articles: Set<Article>) -> [CKRecord] {
|
||||||
|
|
||||||
var articleDict = [String: Article]()
|
var articleDict = [String: Article]()
|
||||||
|
@ -151,8 +172,8 @@ private extension CloudKitArticlesZone {
|
||||||
record![CloudKitArticleStatus.Fields.read] = status.flag ? "1" : "0"
|
record![CloudKitArticleStatus.Fields.read] = status.flag ? "1" : "0"
|
||||||
case .starred:
|
case .starred:
|
||||||
record![CloudKitArticleStatus.Fields.starred] = status.flag ? "1" : "0"
|
record![CloudKitArticleStatus.Fields.starred] = status.flag ? "1" : "0"
|
||||||
case .userDeleted:
|
default:
|
||||||
record![CloudKitArticleStatus.Fields.userDeleted] = status.flag ? "1" : "0"
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,7 +202,8 @@ private extension CloudKitArticlesZoneDelegate {
|
||||||
|
|
||||||
extension CloudKitArticlesZoneDelegate: LocalAccountRefresherDelegate {
|
extension CloudKitArticlesZoneDelegate: LocalAccountRefresherDelegate {
|
||||||
|
|
||||||
func localAccountRefresher(_ refresher: LocalAccountRefresher, didProcess newAndUpdatedArticles: NewAndUpdatedArticles) {
|
func localAccountRefresher(_ refresher: LocalAccountRefresher, didProcess newAndUpdatedArticles: NewAndUpdatedArticles, completion: @escaping () -> Void) {
|
||||||
|
completion()
|
||||||
}
|
}
|
||||||
|
|
||||||
func localAccountRefresher(_ refresher: LocalAccountRefresher, requestCompletedFor: WebFeed) {
|
func localAccountRefresher(_ refresher: LocalAccountRefresher, requestCompletedFor: WebFeed) {
|
||||||
|
|
|
@ -234,7 +234,8 @@ final class LocalAccountDelegate: AccountDelegate {
|
||||||
|
|
||||||
extension LocalAccountDelegate: LocalAccountRefresherDelegate {
|
extension LocalAccountDelegate: LocalAccountRefresherDelegate {
|
||||||
|
|
||||||
func localAccountRefresher(_ refresher: LocalAccountRefresher, didProcess newAndUpdatedArticles: NewAndUpdatedArticles) {
|
func localAccountRefresher(_ refresher: LocalAccountRefresher, didProcess newAndUpdatedArticles: NewAndUpdatedArticles, completion: @escaping () -> Void) {
|
||||||
|
completion()
|
||||||
}
|
}
|
||||||
|
|
||||||
func localAccountRefresher(_ refresher: LocalAccountRefresher, requestCompletedFor: WebFeed) {
|
func localAccountRefresher(_ refresher: LocalAccountRefresher, requestCompletedFor: WebFeed) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ import Articles
|
||||||
import ArticlesDatabase
|
import ArticlesDatabase
|
||||||
|
|
||||||
protocol LocalAccountRefresherDelegate {
|
protocol LocalAccountRefresherDelegate {
|
||||||
func localAccountRefresher(_ refresher: LocalAccountRefresher, didProcess: NewAndUpdatedArticles)
|
func localAccountRefresher(_ refresher: LocalAccountRefresher, didProcess: NewAndUpdatedArticles, completion: @escaping () -> Void)
|
||||||
func localAccountRefresher(_ refresher: LocalAccountRefresher, requestCompletedFor: WebFeed)
|
func localAccountRefresher(_ refresher: LocalAccountRefresher, requestCompletedFor: WebFeed)
|
||||||
func localAccountRefresherDidFinish(_ refresher: LocalAccountRefresher)
|
func localAccountRefresherDidFinish(_ refresher: LocalAccountRefresher)
|
||||||
}
|
}
|
||||||
|
@ -101,14 +101,18 @@ extension LocalAccountRefresher: DownloadSessionDelegate {
|
||||||
|
|
||||||
account.update(feed, with: parsedFeed) { result in
|
account.update(feed, with: parsedFeed) { result in
|
||||||
if case .success(let newAndUpdatedArticles) = result {
|
if case .success(let newAndUpdatedArticles) = result {
|
||||||
self.delegate?.localAccountRefresher(self, didProcess: newAndUpdatedArticles)
|
self.delegate?.localAccountRefresher(self, didProcess: newAndUpdatedArticles) {
|
||||||
if let httpResponse = response as? HTTPURLResponse {
|
if let httpResponse = response as? HTTPURLResponse {
|
||||||
feed.conditionalGetInfo = HTTPConditionalGetInfo(urlResponse: httpResponse)
|
feed.conditionalGetInfo = HTTPConditionalGetInfo(urlResponse: httpResponse)
|
||||||
|
}
|
||||||
|
feed.contentHash = dataHash
|
||||||
|
completion()
|
||||||
|
self.delegate?.localAccountRefresher(self, requestCompletedFor: feed)
|
||||||
}
|
}
|
||||||
feed.contentHash = dataHash
|
} else {
|
||||||
|
completion()
|
||||||
|
self.delegate?.localAccountRefresher(self, requestCompletedFor: feed)
|
||||||
}
|
}
|
||||||
completion()
|
|
||||||
self.delegate?.localAccountRefresher(self, requestCompletedFor: feed)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue