Add optional completions to avoid race conditions involving these marked statuses.

This commit is contained in:
Kiel Gillard 2019-12-18 09:41:45 +11:00
parent 6fb0e2e0d0
commit 7ddcb2fc8e

View File

@ -808,23 +808,23 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
/// Mark articleIDs as read. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification. /// Mark articleIDs as read. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
func markAsRead(_ articleIDs: Set<String>) { func markAsRead(_ articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
mark(articleIDs: articleIDs, statusKey: .read, flag: true) mark(articleIDs: articleIDs, statusKey: .read, flag: true, completion: completion)
} }
/// Mark articleIDs as unread. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification. /// Mark articleIDs as unread. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
func markAsUnread(_ articleIDs: Set<String>) { func markAsUnread(_ articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
mark(articleIDs: articleIDs, statusKey: .read, flag: false) mark(articleIDs: articleIDs, statusKey: .read, flag: false, completion: completion)
} }
/// Mark articleIDs as starred. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification. /// Mark articleIDs as starred. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
func markAsStarred(_ articleIDs: Set<String>) { func markAsStarred(_ articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
mark(articleIDs: articleIDs, statusKey: .starred, flag: true) mark(articleIDs: articleIDs, statusKey: .starred, flag: true, completion: completion)
} }
/// Mark articleIDs as unstarred. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification. /// Mark articleIDs as unstarred. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
func markAsUnstarred(_ articleIDs: Set<String>) { func markAsUnstarred(_ articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
mark(articleIDs: articleIDs, statusKey: .starred, flag: false) mark(articleIDs: articleIDs, statusKey: .starred, flag: false, completion: completion)
} }
/// Empty caches that can reasonably be emptied. Call when the app goes in the background, for instance. /// Empty caches that can reasonably be emptied. Call when the app goes in the background, for instance.