Save article statuses from articles we have not received yet
This commit is contained in:
parent
62d154d0f2
commit
e31e1a4d60
|
@ -617,6 +617,10 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||
|
||||
}
|
||||
|
||||
func ensureStatuses(_ articleIDs: Set<String>, _ statusKey: ArticleStatus.Key, _ flag: Bool) {
|
||||
database.ensureStatuses(articleIDs, statusKey, flag)
|
||||
}
|
||||
|
||||
// MARK: - Container
|
||||
|
||||
public func flattenedFeeds() -> Set<Feed> {
|
||||
|
|
|
@ -1020,17 +1020,28 @@ private extension FeedbinAccountDelegate {
|
|||
let feedbinUnreadArticleIDs = Set(articleIDs.map { String($0) } )
|
||||
let currentUnreadArticleIDs = account.fetchUnreadArticleIDs()
|
||||
|
||||
// Mark articles as unread
|
||||
let deltaUnreadArticleIDs = feedbinUnreadArticleIDs.subtracting(currentUnreadArticleIDs)
|
||||
let markUnreadArticles = account.fetchArticles(forArticleIDs: deltaUnreadArticleIDs)
|
||||
DispatchQueue.main.async {
|
||||
_ = account.markArticles(markUnreadArticles, statusKey: .read, flag: false)
|
||||
}
|
||||
|
||||
// Mark articles as read
|
||||
let deltaReadArticleIDs = currentUnreadArticleIDs.subtracting(feedbinUnreadArticleIDs)
|
||||
let markReadArticles = account.fetchArticles(forArticleIDs: deltaReadArticleIDs)
|
||||
DispatchQueue.main.async {
|
||||
_ = account.markArticles(markReadArticles, statusKey: .read, flag: true)
|
||||
}
|
||||
|
||||
// Save any unread statuses for articles we haven't yet received
|
||||
let markUnreadArticleIDs = Set(markUnreadArticles.map { $0.articleID })
|
||||
let missingUnreadArticleIDs = deltaUnreadArticleIDs.subtracting(markUnreadArticleIDs)
|
||||
if !missingUnreadArticleIDs.isEmpty {
|
||||
DispatchQueue.main.async {
|
||||
account.ensureStatuses(missingUnreadArticleIDs, .read, false)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1043,18 +1054,29 @@ private extension FeedbinAccountDelegate {
|
|||
let feedbinStarredArticleIDs = Set(articleIDs.map { String($0) } )
|
||||
let currentStarredArticleIDs = account.fetchStarredArticleIDs()
|
||||
|
||||
// Mark articles as starred
|
||||
let deltaStarredArticleIDs = feedbinStarredArticleIDs.subtracting(currentStarredArticleIDs)
|
||||
let markStarredArticles = account.fetchArticles(forArticleIDs: deltaStarredArticleIDs)
|
||||
DispatchQueue.main.async {
|
||||
_ = account.markArticles(markStarredArticles, statusKey: .starred, flag: true)
|
||||
}
|
||||
|
||||
// Mark articles as unstarred
|
||||
let deltaUnstarredArticleIDs = currentStarredArticleIDs.subtracting(feedbinStarredArticleIDs)
|
||||
let markUnstarredArticles = account.fetchArticles(forArticleIDs: deltaUnstarredArticleIDs)
|
||||
DispatchQueue.main.async {
|
||||
_ = account.markArticles(markUnstarredArticles, statusKey: .starred, flag: false)
|
||||
}
|
||||
|
||||
// Save any starred statuses for articles we haven't yet received
|
||||
let markStarredArticleIDs = Set(markStarredArticles.map { $0.articleID })
|
||||
let missingStarredArticleIDs = deltaStarredArticleIDs.subtracting(markStarredArticleIDs)
|
||||
if !missingStarredArticleIDs.isEmpty {
|
||||
DispatchQueue.main.async {
|
||||
account.ensureStatuses(missingStarredArticleIDs, .starred, true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -98,6 +98,10 @@ public final class ArticlesDatabase {
|
|||
return articlesTable.update(feedID, parsedItems, defaultRead, completion)
|
||||
}
|
||||
|
||||
public func ensureStatuses(_ articleIDs: Set<String>, _ statusKey: ArticleStatus.Key, _ flag: Bool) {
|
||||
articlesTable.ensureStatuses(articleIDs, statusKey, flag)
|
||||
}
|
||||
|
||||
// MARK: - Status
|
||||
|
||||
public func fetchUnreadArticleIDs() -> Set<String> {
|
||||
|
|
|
@ -185,6 +185,16 @@ final class ArticlesTable: DatabaseTable {
|
|||
}
|
||||
}
|
||||
|
||||
func ensureStatuses(_ articleIDs: Set<String>, _ statusKey: ArticleStatus.Key, _ flag: Bool) {
|
||||
|
||||
self.queue.update { (database) in
|
||||
let statusesDictionary = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, false, database)
|
||||
let statuses = Set(statusesDictionary.values)
|
||||
_ = self.statusesTable.mark(statuses, statusKey, flag)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: Unread Counts
|
||||
|
||||
func fetchUnreadCounts(_ feedIDs: Set<String>, _ completion: @escaping UnreadCountCompletionBlock) {
|
||||
|
|
Loading…
Reference in New Issue