Updated FreshRSS to pull statuses before articles and to work with the new sync status API's
This commit is contained in:
parent
ea1f21797c
commit
995fca5d6a
|
@ -88,8 +88,10 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||||
refreshAccount(account) { result in
|
refreshAccount(account) { result in
|
||||||
switch result {
|
switch result {
|
||||||
case .success():
|
case .success():
|
||||||
self.refreshArticles(account) {
|
|
||||||
|
self.sendArticleStatus(for: account) {
|
||||||
self.refreshArticleStatus(for: account) {
|
self.refreshArticleStatus(for: account) {
|
||||||
|
self.refreshArticles(account) {
|
||||||
self.refreshMissingArticles(account) {
|
self.refreshMissingArticles(account) {
|
||||||
self.refreshProgress.clear()
|
self.refreshProgress.clear()
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
@ -98,6 +100,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
@ -756,8 +759,8 @@ private extension ReaderAPIAccountDelegate {
|
||||||
case .success(let (entries, page)):
|
case .success(let (entries, page)):
|
||||||
|
|
||||||
self.processEntries(account: account, entries: entries) {
|
self.processEntries(account: account, entries: entries) {
|
||||||
self.refreshArticles(account, page: page) {
|
|
||||||
self.refreshArticleStatus(for: account) {
|
self.refreshArticleStatus(for: account) {
|
||||||
|
self.refreshArticles(account, page: page) {
|
||||||
self.refreshMissingArticles(account) {
|
self.refreshMissingArticles(account) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
completion(.success(feed))
|
completion(.success(feed))
|
||||||
|
@ -812,7 +815,7 @@ private extension ReaderAPIAccountDelegate {
|
||||||
os_log(.debug, log: log, "Refreshing missing articles...")
|
os_log(.debug, log: log, "Refreshing missing articles...")
|
||||||
let group = DispatchGroup()
|
let group = DispatchGroup()
|
||||||
|
|
||||||
account.fetchArticleIDsForStatusesWithoutArticles { (fetchedArticleIDs) in
|
let fetchedArticleIDs = account.fetchArticleIDsForStatusesWithoutArticles()
|
||||||
let articleIDs = Array(fetchedArticleIDs)
|
let articleIDs = Array(fetchedArticleIDs)
|
||||||
let chunkedArticleIDs = articleIDs.chunked(into: 100)
|
let chunkedArticleIDs = articleIDs.chunked(into: 100)
|
||||||
|
|
||||||
|
@ -832,7 +835,6 @@ private extension ReaderAPIAccountDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
group.notify(queue: DispatchQueue.main) {
|
group.notify(queue: DispatchQueue.main) {
|
||||||
self.refreshProgress.completeTask()
|
self.refreshProgress.completeTask()
|
||||||
|
@ -918,64 +920,62 @@ private extension ReaderAPIAccountDelegate {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let unreadArticleIDs = Set(articleIDs.map { String($0) } )
|
let feedbinUnreadArticleIDs = Set(articleIDs.map { String($0) } )
|
||||||
account.fetchUnreadArticleIDs { (currentUnreadArticleIDs) in
|
let currentUnreadArticleIDs = account.fetchUnreadArticleIDs()
|
||||||
|
|
||||||
// Mark articles as unread
|
// Mark articles as unread
|
||||||
let deltaUnreadArticleIDs = unreadArticleIDs.subtracting(currentUnreadArticleIDs)
|
let deltaUnreadArticleIDs = feedbinUnreadArticleIDs.subtracting(currentUnreadArticleIDs)
|
||||||
account.fetchArticlesAsync(.articleIDs(deltaUnreadArticleIDs)) { (markUnreadArticles) in
|
let markUnreadArticles = account.fetchArticles(.articleIDs(deltaUnreadArticleIDs))
|
||||||
account.update(markUnreadArticles, statusKey: .read, flag: false)
|
account.update(markUnreadArticles, statusKey: .read, flag: false)
|
||||||
|
|
||||||
// Save any unread statuses for articles we haven't yet received
|
// Save any unread statuses for articles we haven't yet received
|
||||||
let markUnreadArticleIDs = Set(markUnreadArticles.map { $0.articleID })
|
let markUnreadArticleIDs = Set(markUnreadArticles.map { $0.articleID })
|
||||||
let missingUnreadArticleIDs = deltaUnreadArticleIDs.subtracting(markUnreadArticleIDs)
|
let missingUnreadArticleIDs = deltaUnreadArticleIDs.subtracting(markUnreadArticleIDs)
|
||||||
account.ensureStatuses(missingUnreadArticleIDs, .read, false)
|
account.ensureStatuses(missingUnreadArticleIDs, true, .read, false)
|
||||||
}
|
|
||||||
|
|
||||||
// Mark articles as read
|
// Mark articles as read
|
||||||
let deltaReadArticleIDs = currentUnreadArticleIDs.subtracting(unreadArticleIDs)
|
let deltaReadArticleIDs = currentUnreadArticleIDs.subtracting(feedbinUnreadArticleIDs)
|
||||||
account.fetchArticlesAsync(.articleIDs(deltaReadArticleIDs)) { (markReadArticles) in
|
let markReadArticles = account.fetchArticles(.articleIDs(deltaReadArticleIDs))
|
||||||
account.update(markReadArticles, statusKey: .read, flag: true)
|
account.update(markReadArticles, statusKey: .read, flag: true)
|
||||||
|
|
||||||
// Save any read statuses for articles we haven't yet received
|
// Save any read statuses for articles we haven't yet received
|
||||||
let markReadArticleIDs = Set(markReadArticles.map { $0.articleID })
|
let markReadArticleIDs = Set(markReadArticles.map { $0.articleID })
|
||||||
let missingReadArticleIDs = deltaReadArticleIDs.subtracting(markReadArticleIDs)
|
let missingReadArticleIDs = deltaReadArticleIDs.subtracting(markReadArticleIDs)
|
||||||
account.ensureStatuses(missingReadArticleIDs, .read, true)
|
account.ensureStatuses(missingReadArticleIDs, true, .read, true)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func syncArticleStarredState(account: Account, articleIDs: [Int]?) {
|
func syncArticleStarredState(account: Account, articleIDs: [Int]?) {
|
||||||
|
|
||||||
guard let articleIDs = articleIDs else {
|
guard let articleIDs = articleIDs else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let starredArticleIDs = Set(articleIDs.map { String($0) } )
|
let feedbinStarredArticleIDs = Set(articleIDs.map { String($0) } )
|
||||||
account.fetchStarredArticleIDs { (currentStarredArticleIDs) in
|
let currentStarredArticleIDs = account.fetchStarredArticleIDs()
|
||||||
|
|
||||||
// Mark articles as starred
|
// Mark articles as starred
|
||||||
let deltaStarredArticleIDs = starredArticleIDs.subtracting(currentStarredArticleIDs)
|
let deltaStarredArticleIDs = feedbinStarredArticleIDs.subtracting(currentStarredArticleIDs)
|
||||||
account.fetchArticlesAsync(.articleIDs(deltaStarredArticleIDs)) { (markStarredArticles) in
|
let markStarredArticles = account.fetchArticles(.articleIDs(deltaStarredArticleIDs))
|
||||||
account.update(markStarredArticles, statusKey: .starred, flag: true)
|
account.update(markStarredArticles, statusKey: .starred, flag: true)
|
||||||
|
|
||||||
// Save any starred statuses for articles we haven't yet received
|
// Save any starred statuses for articles we haven't yet received
|
||||||
let markStarredArticleIDs = Set(markStarredArticles.map { $0.articleID })
|
let markStarredArticleIDs = Set(markStarredArticles.map { $0.articleID })
|
||||||
let missingStarredArticleIDs = deltaStarredArticleIDs.subtracting(markStarredArticleIDs)
|
let missingStarredArticleIDs = deltaStarredArticleIDs.subtracting(markStarredArticleIDs)
|
||||||
account.ensureStatuses(missingStarredArticleIDs, .starred, true)
|
account.ensureStatuses(missingStarredArticleIDs, true, .starred, true)
|
||||||
}
|
|
||||||
|
|
||||||
// Mark articles as unstarred
|
// Mark articles as unstarred
|
||||||
let deltaUnstarredArticleIDs = currentStarredArticleIDs.subtracting(starredArticleIDs)
|
let deltaUnstarredArticleIDs = currentStarredArticleIDs.subtracting(feedbinStarredArticleIDs)
|
||||||
account.fetchArticlesAsync(.articleIDs(deltaUnstarredArticleIDs)) { (markUnstarredArticles) in
|
let markUnstarredArticles = account.fetchArticles(.articleIDs(deltaUnstarredArticleIDs))
|
||||||
account.update(markUnstarredArticles, statusKey: .starred, flag: false)
|
account.update(markUnstarredArticles, statusKey: .starred, flag: false)
|
||||||
|
|
||||||
// Save any unstarred statuses for articles we haven't yet received
|
// Save any unstarred statuses for articles we haven't yet received
|
||||||
let markUnstarredArticleIDs = Set(markUnstarredArticles.map { $0.articleID })
|
let markUnstarredArticleIDs = Set(markUnstarredArticles.map { $0.articleID })
|
||||||
let missingUnstarredArticleIDs = deltaUnstarredArticleIDs.subtracting(markUnstarredArticleIDs)
|
let missingUnstarredArticleIDs = deltaUnstarredArticleIDs.subtracting(markUnstarredArticleIDs)
|
||||||
account.ensureStatuses(missingUnstarredArticleIDs, .starred, false)
|
account.ensureStatuses(missingUnstarredArticleIDs, true, .starred, false)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func deleteTagging(for account: Account, with feed: Feed, from container: Container?, completion: @escaping (Result<Void, Error>) -> Void) {
|
func deleteTagging(for account: Account, with feed: Feed, from container: Container?, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
|
|
||||||
if let folder = container as? Folder, let feedName = feed.subscriptionID {
|
if let folder = container as? Folder, let feedName = feed.subscriptionID {
|
||||||
|
|
Loading…
Reference in New Issue