mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Implement mark-everywhere-as-read.
This commit is contained in:
@@ -335,6 +335,14 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
database.fetchStarredAndUnreadCount(for: flattenedFeeds(), callback: callback)
|
||||
}
|
||||
|
||||
public func markEverywhereAsRead() {
|
||||
|
||||
// Does not support undo.
|
||||
|
||||
database.markEverywhereAsRead()
|
||||
flattenedFeeds().forEach { $0.unreadCount = 0 }
|
||||
}
|
||||
|
||||
// MARK: - Notifications
|
||||
|
||||
@objc func downloadProgressDidChange(_ note: Notification) {
|
||||
|
||||
@@ -187,6 +187,11 @@ final class ArticlesTable: DatabaseTable {
|
||||
|
||||
return statusesTable.mark(articles.statuses(), statusKey, flag)
|
||||
}
|
||||
|
||||
func markEverywhereAsRead() {
|
||||
|
||||
return statusesTable.markEverywhereAsRead()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@@ -84,5 +84,10 @@ public final class Database {
|
||||
|
||||
return articlesTable.mark(articles, statusKey, flag)
|
||||
}
|
||||
|
||||
public func markEverywhereAsRead() {
|
||||
|
||||
articlesTable.markEverywhereAsRead()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,20 @@ final class StatusesTable: DatabaseTable {
|
||||
return updatedStatuses
|
||||
}
|
||||
|
||||
func markEverywhereAsRead() {
|
||||
|
||||
queue.update { (database) in
|
||||
|
||||
let _ = database.executeUpdate("update statuses set read=1;", withArgumentsIn: nil)
|
||||
|
||||
let cachedStatuses = self.cache.cachedStatuses
|
||||
|
||||
DispatchQueue.main.async {
|
||||
cachedStatuses.forEach { $0.read = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Fetching
|
||||
|
||||
func statusWithRow(_ row: FMResultSet) -> ArticleStatus? {
|
||||
@@ -164,6 +178,11 @@ private final class StatusCache {
|
||||
// Serial database queue only.
|
||||
|
||||
var dictionary = [String: ArticleStatus]()
|
||||
var cachedStatuses: Set<ArticleStatus> {
|
||||
get {
|
||||
return Set(dictionary.values)
|
||||
}
|
||||
}
|
||||
|
||||
func add(_ statuses: Set<ArticleStatus>) {
|
||||
|
||||
@@ -191,7 +210,7 @@ private final class StatusCache {
|
||||
self[articleID] = status
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
subscript(_ articleID: String) -> ArticleStatus? {
|
||||
get {
|
||||
return dictionary[articleID]
|
||||
|
||||
Reference in New Issue
Block a user