Set default read state for Feedbin articles to read when syncing

This commit is contained in:
Maurice Parker 2019-05-13 08:32:03 -05:00
parent c47fee2384
commit c4ce93e96a
6 changed files with 13 additions and 13 deletions

View File

@ -582,9 +582,9 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
update(feed, parsedItems: parsedFeed.items, completion)
}
func update(_ feed: Feed, parsedItems: Set<ParsedItem>, _ completion: @escaping (() -> Void)) {
func update(_ feed: Feed, parsedItems: Set<ParsedItem>, defaultRead: Bool = false, _ completion: @escaping (() -> Void)) {
database.update(feedID: feed.feedID, parsedItems: parsedItems) { (newArticles, updatedArticles) in
database.update(feedID: feed.feedID, parsedItems: parsedItems, defaultRead: defaultRead) { (newArticles, updatedArticles) in
var userInfo = [String: Any]()
if let newArticles = newArticles, !newArticles.isEmpty {

View File

@ -917,7 +917,7 @@ private extension FeedbinAccountDelegate {
for (feedID, mapItems) in parsedMap {
if let feed = account.idToFeedDictionary[feedID] {
DispatchQueue.main.async {
account.update(feed, parsedItems: Set(mapItems)) {
account.update(feed, parsedItems: Set(mapItems), defaultRead: true) {
completion()
}
}

View File

@ -38,9 +38,9 @@ public final class ArticleStatus: Hashable {
self.dateArrived = dateArrived
}
public convenience init(articleID: String, dateArrived: Date) {
public convenience init(articleID: String, read: Bool, dateArrived: Date) {
self.init(articleID: articleID, read: false, starred: false, userDeleted: false, dateArrived: dateArrived)
self.init(articleID: articleID, read: read, starred: false, userDeleted: false, dateArrived: dateArrived)
}
public func boolStatus(forKey key: ArticleStatus.Key) -> Bool {

View File

@ -90,8 +90,8 @@ public final class ArticlesDatabase {
// MARK: - Saving and Updating Articles
public func update(feedID: String, parsedItems: Set<ParsedItem>, completion: @escaping UpdateArticlesWithFeedCompletionBlock) {
return articlesTable.update(feedID, parsedItems, completion)
public func update(feedID: String, parsedItems: Set<ParsedItem>, defaultRead: Bool, completion: @escaping UpdateArticlesWithFeedCompletionBlock) {
return articlesTable.update(feedID, parsedItems, defaultRead, completion)
}
// MARK: - Status

View File

@ -119,7 +119,7 @@ final class ArticlesTable: DatabaseTable {
// MARK: Updating
func update(_ feedID: String, _ parsedItems: Set<ParsedItem>, _ completion: @escaping UpdateArticlesWithFeedCompletionBlock) {
func update(_ feedID: String, _ parsedItems: Set<ParsedItem>, _ read: Bool, _ completion: @escaping UpdateArticlesWithFeedCompletionBlock) {
if parsedItems.isEmpty {
completion(nil, nil)
@ -139,7 +139,7 @@ final class ArticlesTable: DatabaseTable {
self.queue.update { (database) in
let statusesDictionary = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, database) //1
let statusesDictionary = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, read, database) //1
assert(statusesDictionary.count == articleIDs.count)
let allIncomingArticles = Article.articlesWithParsedItems(parsedItems, self.accountID, feedID, statusesDictionary) //2

View File

@ -28,7 +28,7 @@ final class StatusesTable: DatabaseTable {
// MARK: Creating/Updating
func ensureStatusesForArticleIDs(_ articleIDs: Set<String>, _ database: FMDatabase) -> [String: ArticleStatus] {
func ensureStatusesForArticleIDs(_ articleIDs: Set<String>, _ read: Bool, _ database: FMDatabase) -> [String: ArticleStatus] {
// Check cache.
let articleIDsMissingCachedStatus = articleIDsWithNoCachedStatus(articleIDs)
@ -42,7 +42,7 @@ final class StatusesTable: DatabaseTable {
let articleIDsNeedingStatus = self.articleIDsWithNoCachedStatus(articleIDs)
if !articleIDsNeedingStatus.isEmpty {
// Create new statuses.
self.createAndSaveStatusesForArticleIDs(articleIDsNeedingStatus, database)
self.createAndSaveStatusesForArticleIDs(articleIDsNeedingStatus, read, database)
}
return statusesDictionary(articleIDs)
@ -130,10 +130,10 @@ private extension StatusesTable {
self.insertRows(statusArray, insertType: .orIgnore, in: database)
}
func createAndSaveStatusesForArticleIDs(_ articleIDs: Set<String>, _ database: FMDatabase) {
func createAndSaveStatusesForArticleIDs(_ articleIDs: Set<String>, _ read: Bool, _ database: FMDatabase) {
let now = Date()
let statuses = Set(articleIDs.map { ArticleStatus(articleID: $0, dateArrived: now) })
let statuses = Set(articleIDs.map { ArticleStatus(articleID: $0, read: read, dateArrived: now) })
cache.addIfNotCached(statuses)
saveStatuses(statuses, database)