Rename callback: to completion:

This commit is contained in:
Maurice Parker 2019-12-14 18:01:34 -07:00
parent 43bf65b7a6
commit 58b24f3349
26 changed files with 196 additions and 196 deletions

View File

@ -642,45 +642,45 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
} }
public func fetchArticlesAsync(_ fetchType: FetchType, _ callback: @escaping ArticleSetBlock) { public func fetchArticlesAsync(_ fetchType: FetchType, _ completion: @escaping ArticleSetBlock) {
switch fetchType { switch fetchType {
case .starred: case .starred:
fetchStarredArticlesAsync(callback) fetchStarredArticlesAsync(completion)
case .unread: case .unread:
fetchUnreadArticlesAsync(callback) fetchUnreadArticlesAsync(completion)
case .today: case .today:
fetchTodayArticlesAsync(callback) fetchTodayArticlesAsync(completion)
case .folder(let folder, let readFilter): case .folder(let folder, let readFilter):
if readFilter { if readFilter {
return fetchUnreadArticlesAsync(folder: folder, callback) return fetchUnreadArticlesAsync(folder: folder, completion)
} else { } else {
return fetchArticlesAsync(folder: folder, callback) return fetchArticlesAsync(folder: folder, completion)
} }
case .webFeed(let webFeed): case .webFeed(let webFeed):
fetchArticlesAsync(webFeed: webFeed, callback) fetchArticlesAsync(webFeed: webFeed, completion)
case .articleIDs(let articleIDs): case .articleIDs(let articleIDs):
fetchArticlesAsync(articleIDs: articleIDs, callback) fetchArticlesAsync(articleIDs: articleIDs, completion)
case .search(let searchString): case .search(let searchString):
fetchArticlesMatchingAsync(searchString, callback) fetchArticlesMatchingAsync(searchString, completion)
case .searchWithArticleIDs(let searchString, let articleIDs): case .searchWithArticleIDs(let searchString, let articleIDs):
return fetchArticlesMatchingWithArticleIDsAsync(searchString, articleIDs, callback) return fetchArticlesMatchingWithArticleIDsAsync(searchString, articleIDs, completion)
} }
} }
public func fetchUnreadCountForToday(_ callback: @escaping (Int) -> Void) { public func fetchUnreadCountForToday(_ completion: @escaping (Int) -> Void) {
database.fetchUnreadCountForToday(for: flattenedWebFeeds().webFeedIDs(), callback: callback) database.fetchUnreadCountForToday(for: flattenedWebFeeds().webFeedIDs(), completion: completion)
} }
public func fetchUnreadCountForStarredArticles(_ callback: @escaping (Int) -> Void) { public func fetchUnreadCountForStarredArticles(_ completion: @escaping (Int) -> Void) {
database.fetchStarredAndUnreadCount(for: flattenedWebFeeds().webFeedIDs(), callback: callback) database.fetchStarredAndUnreadCount(for: flattenedWebFeeds().webFeedIDs(), completion: completion)
} }
public func fetchUnreadArticleIDs(_ callback: @escaping (Set<String>) -> Void) { public func fetchUnreadArticleIDs(_ completion: @escaping (Set<String>) -> Void) {
database.fetchUnreadArticleIDsAsync(webFeedIDs: flattenedWebFeeds().webFeedIDs(), callback: callback) database.fetchUnreadArticleIDsAsync(webFeedIDs: flattenedWebFeeds().webFeedIDs(), completion: completion)
} }
public func fetchStarredArticleIDs(_ callback: @escaping (Set<String>) -> Void) { public func fetchStarredArticleIDs(_ completion: @escaping (Set<String>) -> Void) {
database.fetchStarredArticleIDsAsync(webFeedIDs: flattenedWebFeeds().webFeedIDs(), callback: callback) database.fetchStarredArticleIDsAsync(webFeedIDs: flattenedWebFeeds().webFeedIDs(), completion: completion)
} }
public func fetchArticleIDsForStatusesWithoutArticles() -> Set<String> { public func fetchArticleIDsForStatusesWithoutArticles() -> Set<String> {
@ -770,7 +770,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
/// Fetch statuses for the specified articleIDs. The completion handler will get nil if the app is suspended. /// Fetch statuses for the specified articleIDs. The completion handler will get nil if the app is suspended.
/// To update the properties in the database, call the update method that takes Set<ArticleStatus> as first parameter. /// To update the properties in the database, call the update method that takes Set<ArticleStatus> as first parameter.
func fetchStatuses(articleIDs: Set<String>, createIfNeeded: Bool, completion: @escaping (Set<ArticleStatus>?) -> Void) { func fetchStatuses(articleIDs: Set<String>, createIfNeeded: Bool, completion: @escaping (Set<ArticleStatus>?) -> Void) {
database.fetchStatuses(articleIDs: articleIDs, createIfNeeded: createIfNeeded, callback: completion) database.fetchStatuses(articleIDs: articleIDs, createIfNeeded: createIfNeeded, 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.
@ -923,40 +923,40 @@ private extension Account {
return database.fetchStarredArticles(flattenedWebFeeds().webFeedIDs()) return database.fetchStarredArticles(flattenedWebFeeds().webFeedIDs())
} }
func fetchStarredArticlesAsync(_ callback: @escaping ArticleSetBlock) { func fetchStarredArticlesAsync(_ completion: @escaping ArticleSetBlock) {
database.fetchedStarredArticlesAsync(flattenedWebFeeds().webFeedIDs(), callback) database.fetchedStarredArticlesAsync(flattenedWebFeeds().webFeedIDs(), completion)
} }
func fetchUnreadArticles() -> Set<Article> { func fetchUnreadArticles() -> Set<Article> {
return fetchUnreadArticles(forContainer: self) return fetchUnreadArticles(forContainer: self)
} }
func fetchUnreadArticlesAsync(_ callback: @escaping ArticleSetBlock) { func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetBlock) {
fetchUnreadArticlesAsync(forContainer: self, callback) fetchUnreadArticlesAsync(forContainer: self, completion)
} }
func fetchTodayArticles() -> Set<Article> { func fetchTodayArticles() -> Set<Article> {
return database.fetchTodayArticles(flattenedWebFeeds().webFeedIDs()) return database.fetchTodayArticles(flattenedWebFeeds().webFeedIDs())
} }
func fetchTodayArticlesAsync(_ callback: @escaping ArticleSetBlock) { func fetchTodayArticlesAsync(_ completion: @escaping ArticleSetBlock) {
database.fetchTodayArticlesAsync(flattenedWebFeeds().webFeedIDs(), callback) database.fetchTodayArticlesAsync(flattenedWebFeeds().webFeedIDs(), completion)
} }
func fetchArticles(folder: Folder) -> Set<Article> { func fetchArticles(folder: Folder) -> Set<Article> {
return fetchArticles(forContainer: folder) return fetchArticles(forContainer: folder)
} }
func fetchArticlesAsync(folder: Folder, _ callback: @escaping ArticleSetBlock) { func fetchArticlesAsync(folder: Folder, _ completion: @escaping ArticleSetBlock) {
fetchArticlesAsync(forContainer: folder, callback) fetchArticlesAsync(forContainer: folder, completion)
} }
func fetchUnreadArticles(folder: Folder) -> Set<Article> { func fetchUnreadArticles(folder: Folder) -> Set<Article> {
return fetchUnreadArticles(forContainer: folder) return fetchUnreadArticles(forContainer: folder)
} }
func fetchUnreadArticlesAsync(folder: Folder, _ callback: @escaping ArticleSetBlock) { func fetchUnreadArticlesAsync(folder: Folder, _ completion: @escaping ArticleSetBlock) {
fetchUnreadArticlesAsync(forContainer: folder, callback) fetchUnreadArticlesAsync(forContainer: folder, completion)
} }
func fetchArticles(webFeed: WebFeed) -> Set<Article> { func fetchArticles(webFeed: WebFeed) -> Set<Article> {
@ -965,10 +965,10 @@ private extension Account {
return articles return articles
} }
func fetchArticlesAsync(webFeed: WebFeed, _ callback: @escaping ArticleSetBlock) { func fetchArticlesAsync(webFeed: WebFeed, _ completion: @escaping ArticleSetBlock) {
database.fetchArticlesAsync(webFeed.webFeedID) { [weak self] (articles) in database.fetchArticlesAsync(webFeed.webFeedID) { [weak self] (articles) in
self?.validateUnreadCount(webFeed, articles) self?.validateUnreadCount(webFeed, articles)
callback(articles) completion(articles)
} }
} }
@ -980,20 +980,20 @@ private extension Account {
return database.fetchArticlesMatchingWithArticleIDs(searchString, articleIDs) return database.fetchArticlesMatchingWithArticleIDs(searchString, articleIDs)
} }
func fetchArticlesMatchingAsync(_ searchString: String, _ callback: @escaping ArticleSetBlock) { func fetchArticlesMatchingAsync(_ searchString: String, _ completion: @escaping ArticleSetBlock) {
database.fetchArticlesMatchingAsync(searchString, flattenedWebFeeds().webFeedIDs(), callback) database.fetchArticlesMatchingAsync(searchString, flattenedWebFeeds().webFeedIDs(), completion)
} }
func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
database.fetchArticlesMatchingWithArticleIDsAsync(searchString, articleIDs, callback) database.fetchArticlesMatchingWithArticleIDsAsync(searchString, articleIDs, completion)
} }
func fetchArticles(articleIDs: Set<String>) -> Set<Article> { func fetchArticles(articleIDs: Set<String>) -> Set<Article> {
return database.fetchArticles(articleIDs: articleIDs) return database.fetchArticles(articleIDs: articleIDs)
} }
func fetchArticlesAsync(articleIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { func fetchArticlesAsync(articleIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
return database.fetchArticlesAsync(articleIDs: articleIDs, callback) return database.fetchArticlesAsync(articleIDs: articleIDs, completion)
} }
func fetchUnreadArticles(webFeed: WebFeed) -> Set<Article> { func fetchUnreadArticles(webFeed: WebFeed) -> Set<Article> {
@ -1002,7 +1002,7 @@ private extension Account {
return articles return articles
} }
func fetchUnreadArticlesAsync(for webFeed: WebFeed, callback: @escaping (Set<Article>) -> Void) { func fetchUnreadArticlesAsync(for webFeed: WebFeed, completion: @escaping (Set<Article>) -> Void) {
// database.fetchUnreadArticlesAsync(for: Set([feed.feedID])) { [weak self] (articles) in // database.fetchUnreadArticlesAsync(for: Set([feed.feedID])) { [weak self] (articles) in
// self?.validateUnreadCount(feed, articles) // self?.validateUnreadCount(feed, articles)
// callback(articles) // callback(articles)
@ -1017,11 +1017,11 @@ private extension Account {
return articles return articles
} }
func fetchArticlesAsync(forContainer container: Container, _ callback: @escaping ArticleSetBlock) { func fetchArticlesAsync(forContainer container: Container, _ completion: @escaping ArticleSetBlock) {
let webFeeds = container.flattenedWebFeeds() let webFeeds = container.flattenedWebFeeds()
database.fetchArticlesAsync(webFeeds.webFeedIDs()) { [weak self] (articles) in database.fetchArticlesAsync(webFeeds.webFeedIDs()) { [weak self] (articles) in
self?.validateUnreadCountsAfterFetchingUnreadArticles(webFeeds, articles) self?.validateUnreadCountsAfterFetchingUnreadArticles(webFeeds, articles)
callback(articles) completion(articles)
} }
} }
@ -1032,11 +1032,11 @@ private extension Account {
return articles return articles
} }
func fetchUnreadArticlesAsync(forContainer container: Container, _ callback: @escaping ArticleSetBlock) { func fetchUnreadArticlesAsync(forContainer container: Container, _ completion: @escaping ArticleSetBlock) {
let webFeeds = container.flattenedWebFeeds() let webFeeds = container.flattenedWebFeeds()
database.fetchUnreadArticlesAsync(webFeeds.webFeedIDs()) { [weak self] (articles) in database.fetchUnreadArticlesAsync(webFeeds.webFeedIDs()) { [weak self] (articles) in
self?.validateUnreadCountsAfterFetchingUnreadArticles(webFeeds, articles) self?.validateUnreadCountsAfterFetchingUnreadArticles(webFeeds, articles)
callback(articles) completion(articles)
} }
} }

View File

@ -265,7 +265,7 @@ public final class AccountManager: UnreadCountProvider {
return articles return articles
} }
public func fetchArticlesAsync(_ fetchType: FetchType, _ callback: @escaping ArticleSetBlock) { public func fetchArticlesAsync(_ fetchType: FetchType, _ completion: @escaping ArticleSetBlock) {
precondition(Thread.isMainThread) precondition(Thread.isMainThread)
var allFetchedArticles = Set<Article>() var allFetchedArticles = Set<Article>()
@ -277,7 +277,7 @@ public final class AccountManager: UnreadCountProvider {
allFetchedArticles.formUnion(articles) allFetchedArticles.formUnion(articles)
accountsReporting += 1 accountsReporting += 1
if accountsReporting == numberOfAccounts { if accountsReporting == numberOfAccounts {
callback(allFetchedArticles) completion(allFetchedArticles)
} }
} }
} }

View File

@ -12,9 +12,9 @@ import Articles
public protocol ArticleFetcher { public protocol ArticleFetcher {
func fetchArticles() -> Set<Article> func fetchArticles() -> Set<Article>
func fetchArticlesAsync(_ callback: @escaping ArticleSetBlock) func fetchArticlesAsync(_ completion: @escaping ArticleSetBlock)
func fetchUnreadArticles() -> Set<Article> func fetchUnreadArticles() -> Set<Article>
func fetchUnreadArticlesAsync(_ callback: @escaping ArticleSetBlock) func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetBlock)
} }
extension WebFeed: ArticleFetcher { extension WebFeed: ArticleFetcher {
@ -23,26 +23,26 @@ extension WebFeed: ArticleFetcher {
return account?.fetchArticles(.webFeed(self)) ?? Set<Article>() return account?.fetchArticles(.webFeed(self)) ?? Set<Article>()
} }
public func fetchArticlesAsync(_ callback: @escaping ArticleSetBlock) { public func fetchArticlesAsync(_ completion: @escaping ArticleSetBlock) {
guard let account = account else { guard let account = account else {
assertionFailure("Expected feed.account, but got nil.") assertionFailure("Expected feed.account, but got nil.")
callback(Set<Article>()) completion(Set<Article>())
return return
} }
account.fetchArticlesAsync(.webFeed(self), callback) account.fetchArticlesAsync(.webFeed(self), completion)
} }
public func fetchUnreadArticles() -> Set<Article> { public func fetchUnreadArticles() -> Set<Article> {
return fetchArticles().unreadArticles() return fetchArticles().unreadArticles()
} }
public func fetchUnreadArticlesAsync(_ callback: @escaping ArticleSetBlock) { public func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetBlock) {
guard let account = account else { guard let account = account else {
assertionFailure("Expected feed.account, but got nil.") assertionFailure("Expected feed.account, but got nil.")
callback(Set<Article>()) completion(Set<Article>())
return return
} }
account.fetchArticlesAsync(.webFeed(self)) { callback($0.unreadArticles()) } account.fetchArticlesAsync(.webFeed(self)) { completion($0.unreadArticles()) }
} }
} }
@ -56,13 +56,13 @@ extension Folder: ArticleFetcher {
return account.fetchArticles(.folder(self, false)) return account.fetchArticles(.folder(self, false))
} }
public func fetchArticlesAsync(_ callback: @escaping ArticleSetBlock) { public func fetchArticlesAsync(_ completion: @escaping ArticleSetBlock) {
guard let account = account else { guard let account = account else {
assertionFailure("Expected folder.account, but got nil.") assertionFailure("Expected folder.account, but got nil.")
callback(Set<Article>()) completion(Set<Article>())
return return
} }
account.fetchArticlesAsync(.folder(self, false), callback) account.fetchArticlesAsync(.folder(self, false), completion)
} }
public func fetchUnreadArticles() -> Set<Article> { public func fetchUnreadArticles() -> Set<Article> {
@ -73,12 +73,12 @@ extension Folder: ArticleFetcher {
return account.fetchArticles(.folder(self, true)) return account.fetchArticles(.folder(self, true))
} }
public func fetchUnreadArticlesAsync(_ callback: @escaping ArticleSetBlock) { public func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetBlock) {
guard let account = account else { guard let account = account else {
assertionFailure("Expected folder.account, but got nil.") assertionFailure("Expected folder.account, but got nil.")
callback(Set<Article>()) completion(Set<Article>())
return return
} }
account.fetchArticlesAsync(.folder(self, true), callback) account.fetchArticlesAsync(.folder(self, true), completion)
} }
} }

View File

@ -23,16 +23,16 @@ public struct SingleArticleFetcher: ArticleFetcher {
return account.fetchArticles(.articleIDs(Set([articleID]))) return account.fetchArticles(.articleIDs(Set([articleID])))
} }
public func fetchArticlesAsync(_ callback: @escaping ArticleSetBlock) { public func fetchArticlesAsync(_ completion: @escaping ArticleSetBlock) {
return account.fetchArticlesAsync(.articleIDs(Set([articleID])), callback) return account.fetchArticlesAsync(.articleIDs(Set([articleID])), completion)
} }
public func fetchUnreadArticles() -> Set<Article> { public func fetchUnreadArticles() -> Set<Article> {
return account.fetchArticles(.articleIDs(Set([articleID]))) return account.fetchArticles(.articleIDs(Set([articleID])))
} }
public func fetchUnreadArticlesAsync(_ callback: @escaping ArticleSetBlock) { public func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetBlock) {
return account.fetchArticlesAsync(.articleIDs(Set([articleID])), callback) return account.fetchArticlesAsync(.articleIDs(Set([articleID])), completion)
} }
} }

View File

@ -87,58 +87,58 @@ public final class ArticlesDatabase {
// MARK: - Fetching Articles Async // MARK: - Fetching Articles Async
public func fetchArticlesAsync(_ webFeedID: String, _ callback: @escaping ArticleSetBlock) { public func fetchArticlesAsync(_ webFeedID: String, _ completion: @escaping ArticleSetBlock) {
articlesTable.fetchArticlesAsync(webFeedID, callback) articlesTable.fetchArticlesAsync(webFeedID, completion)
} }
public func fetchArticlesAsync(_ webFeedIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { public func fetchArticlesAsync(_ webFeedIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
articlesTable.fetchArticlesAsync(webFeedIDs, callback) articlesTable.fetchArticlesAsync(webFeedIDs, completion)
} }
public func fetchArticlesAsync(articleIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { public func fetchArticlesAsync(articleIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
articlesTable.fetchArticlesAsync(articleIDs: articleIDs, callback) articlesTable.fetchArticlesAsync(articleIDs: articleIDs, completion)
} }
public func fetchUnreadArticlesAsync(_ webFeedIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { public func fetchUnreadArticlesAsync(_ webFeedIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
articlesTable.fetchUnreadArticlesAsync(webFeedIDs, callback) articlesTable.fetchUnreadArticlesAsync(webFeedIDs, completion)
} }
public func fetchTodayArticlesAsync(_ webFeedIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { public func fetchTodayArticlesAsync(_ webFeedIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
articlesTable.fetchArticlesSinceAsync(webFeedIDs, todayCutoffDate(), callback) articlesTable.fetchArticlesSinceAsync(webFeedIDs, todayCutoffDate(), completion)
} }
public func fetchedStarredArticlesAsync(_ webFeedIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { public func fetchedStarredArticlesAsync(_ webFeedIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
articlesTable.fetchStarredArticlesAsync(webFeedIDs, callback) articlesTable.fetchStarredArticlesAsync(webFeedIDs, completion)
} }
public func fetchArticlesMatchingAsync(_ searchString: String, _ webFeedIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { public func fetchArticlesMatchingAsync(_ searchString: String, _ webFeedIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
articlesTable.fetchArticlesMatchingAsync(searchString, webFeedIDs, callback) articlesTable.fetchArticlesMatchingAsync(searchString, webFeedIDs, completion)
} }
public func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { public func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
articlesTable.fetchArticlesMatchingWithArticleIDsAsync(searchString, articleIDs, callback) articlesTable.fetchArticlesMatchingWithArticleIDsAsync(searchString, articleIDs, completion)
} }
// MARK: - Unread Counts // MARK: - Unread Counts
public func fetchUnreadCounts(for webFeedIDs: Set<String>, _ callback: @escaping UnreadCountCompletionBlock) { public func fetchUnreadCounts(for webFeedIDs: Set<String>, _ completion: @escaping UnreadCountCompletionBlock) {
articlesTable.fetchUnreadCounts(webFeedIDs, callback) articlesTable.fetchUnreadCounts(webFeedIDs, completion)
} }
public func fetchUnreadCountForToday(for webFeedIDs: Set<String>, callback: @escaping (Int) -> Void) { public func fetchUnreadCountForToday(for webFeedIDs: Set<String>, completion: @escaping (Int) -> Void) {
fetchUnreadCount(for: webFeedIDs, since: todayCutoffDate(), callback: callback) fetchUnreadCount(for: webFeedIDs, since: todayCutoffDate(), completion: completion)
} }
public func fetchUnreadCount(for webFeedIDs: Set<String>, since: Date, callback: @escaping (Int) -> Void) { public func fetchUnreadCount(for webFeedIDs: Set<String>, since: Date, completion: @escaping (Int) -> Void) {
articlesTable.fetchUnreadCount(webFeedIDs, since, callback) articlesTable.fetchUnreadCount(webFeedIDs, since, completion)
} }
public func fetchStarredAndUnreadCount(for webFeedIDs: Set<String>, callback: @escaping (Int) -> Void) { public func fetchStarredAndUnreadCount(for webFeedIDs: Set<String>, completion: @escaping (Int) -> Void) {
articlesTable.fetchStarredAndUnreadCount(webFeedIDs, callback) articlesTable.fetchStarredAndUnreadCount(webFeedIDs, completion)
} }
public func fetchAllNonZeroUnreadCounts(_ callback: @escaping UnreadCountCompletionBlock) { public func fetchAllNonZeroUnreadCounts(_ completion: @escaping UnreadCountCompletionBlock) {
articlesTable.fetchAllUnreadCounts(callback) articlesTable.fetchAllUnreadCounts(completion)
} }
// MARK: - Saving and Updating Articles // MARK: - Saving and Updating Articles
@ -155,13 +155,13 @@ public final class ArticlesDatabase {
// MARK: - Status // MARK: - Status
/// Fetch the articleIDs of unread articles in feeds specified by webFeedIDs. /// Fetch the articleIDs of unread articles in feeds specified by webFeedIDs.
public func fetchUnreadArticleIDsAsync(webFeedIDs: Set<String>, callback: @escaping (Set<String>) -> Void) { public func fetchUnreadArticleIDsAsync(webFeedIDs: Set<String>, completion: @escaping (Set<String>) -> Void) {
articlesTable.fetchUnreadArticleIDsAsync(webFeedIDs, callback) articlesTable.fetchUnreadArticleIDsAsync(webFeedIDs, completion)
} }
/// Fetch the articleIDs of starred articles in feeds specified by webFeedIDs. /// Fetch the articleIDs of starred articles in feeds specified by webFeedIDs.
public func fetchStarredArticleIDsAsync(webFeedIDs: Set<String>, callback: @escaping (Set<String>) -> Void) { public func fetchStarredArticleIDsAsync(webFeedIDs: Set<String>, completion: @escaping (Set<String>) -> Void) {
articlesTable.fetchStarredArticleIDsAsync(webFeedIDs, callback) articlesTable.fetchStarredArticleIDsAsync(webFeedIDs, completion)
} }
public func fetchArticleIDsForStatusesWithoutArticles() -> Set<String> { public func fetchArticleIDsForStatusesWithoutArticles() -> Set<String> {
@ -172,8 +172,8 @@ public final class ArticlesDatabase {
return articlesTable.mark(articles, statusKey, flag) return articlesTable.mark(articles, statusKey, flag)
} }
public func fetchStatuses(articleIDs: Set<String>, createIfNeeded: Bool, callback: @escaping (Set<ArticleStatus>?) -> Void) { public func fetchStatuses(articleIDs: Set<String>, createIfNeeded: Bool, completion: @escaping (Set<ArticleStatus>?) -> Void) {
articlesTable.fetchStatuses(articleIDs, createIfNeeded, callback) articlesTable.fetchStatuses(articleIDs, createIfNeeded, completion)
} }
// MARK: - Suspend and Resume (for iOS) // MARK: - Suspend and Resume (for iOS)

View File

@ -47,8 +47,8 @@ final class ArticlesTable: DatabaseTable {
return fetchArticles{ self.fetchArticlesForFeedID(webFeedID, withLimits: true, $0) } return fetchArticles{ self.fetchArticlesForFeedID(webFeedID, withLimits: true, $0) }
} }
func fetchArticlesAsync(_ webFeedID: String, _ callback: @escaping ArticleSetBlock) { func fetchArticlesAsync(_ webFeedID: String, _ completion: @escaping ArticleSetBlock) {
fetchArticlesAsync({ self.fetchArticlesForFeedID(webFeedID, withLimits: true, $0) }, callback) fetchArticlesAsync({ self.fetchArticlesForFeedID(webFeedID, withLimits: true, $0) }, completion)
} }
private func fetchArticlesForFeedID(_ webFeedID: String, withLimits: Bool, _ database: FMDatabase) -> Set<Article> { private func fetchArticlesForFeedID(_ webFeedID: String, withLimits: Bool, _ database: FMDatabase) -> Set<Article> {
@ -59,8 +59,8 @@ final class ArticlesTable: DatabaseTable {
return fetchArticles{ self.fetchArticles(webFeedIDs, $0) } return fetchArticles{ self.fetchArticles(webFeedIDs, $0) }
} }
func fetchArticlesAsync(_ webFeedIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { func fetchArticlesAsync(_ webFeedIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
fetchArticlesAsync({ self.fetchArticles(webFeedIDs, $0) }, callback) fetchArticlesAsync({ self.fetchArticles(webFeedIDs, $0) }, completion)
} }
private func fetchArticles(_ webFeedIDs: Set<String>, _ database: FMDatabase) -> Set<Article> { private func fetchArticles(_ webFeedIDs: Set<String>, _ database: FMDatabase) -> Set<Article> {
@ -80,8 +80,8 @@ final class ArticlesTable: DatabaseTable {
return fetchArticles{ self.fetchArticles(articleIDs: articleIDs, $0) } return fetchArticles{ self.fetchArticles(articleIDs: articleIDs, $0) }
} }
func fetchArticlesAsync(articleIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { func fetchArticlesAsync(articleIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
return fetchArticlesAsync({ self.fetchArticles(articleIDs: articleIDs, $0) }, callback) return fetchArticlesAsync({ self.fetchArticles(articleIDs: articleIDs, $0) }, completion)
} }
private func fetchArticles(articleIDs: Set<String>, _ database: FMDatabase) -> Set<Article> { private func fetchArticles(articleIDs: Set<String>, _ database: FMDatabase) -> Set<Article> {
@ -100,8 +100,8 @@ final class ArticlesTable: DatabaseTable {
return fetchArticles{ self.fetchUnreadArticles(webFeedIDs, $0) } return fetchArticles{ self.fetchUnreadArticles(webFeedIDs, $0) }
} }
func fetchUnreadArticlesAsync(_ webFeedIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { func fetchUnreadArticlesAsync(_ webFeedIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
fetchArticlesAsync({ self.fetchUnreadArticles(webFeedIDs, $0) }, callback) fetchArticlesAsync({ self.fetchUnreadArticles(webFeedIDs, $0) }, completion)
} }
private func fetchUnreadArticles(_ webFeedIDs: Set<String>, _ database: FMDatabase) -> Set<Article> { private func fetchUnreadArticles(_ webFeedIDs: Set<String>, _ database: FMDatabase) -> Set<Article> {
@ -121,8 +121,8 @@ final class ArticlesTable: DatabaseTable {
return fetchArticles{ self.fetchArticlesSince(webFeedIDs, cutoffDate, $0) } return fetchArticles{ self.fetchArticlesSince(webFeedIDs, cutoffDate, $0) }
} }
func fetchArticlesSinceAsync(_ webFeedIDs: Set<String>, _ cutoffDate: Date, _ callback: @escaping ArticleSetBlock) { func fetchArticlesSinceAsync(_ webFeedIDs: Set<String>, _ cutoffDate: Date, _ completion: @escaping ArticleSetBlock) {
fetchArticlesAsync({ self.fetchArticlesSince(webFeedIDs, cutoffDate, $0) }, callback) fetchArticlesAsync({ self.fetchArticlesSince(webFeedIDs, cutoffDate, $0) }, completion)
} }
private func fetchArticlesSince(_ webFeedIDs: Set<String>, _ cutoffDate: Date, _ database: FMDatabase) -> Set<Article> { private func fetchArticlesSince(_ webFeedIDs: Set<String>, _ cutoffDate: Date, _ database: FMDatabase) -> Set<Article> {
@ -144,8 +144,8 @@ final class ArticlesTable: DatabaseTable {
return fetchArticles{ self.fetchStarredArticles(webFeedIDs, $0) } return fetchArticles{ self.fetchStarredArticles(webFeedIDs, $0) }
} }
func fetchStarredArticlesAsync(_ webFeedIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { func fetchStarredArticlesAsync(_ webFeedIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
fetchArticlesAsync({ self.fetchStarredArticles(webFeedIDs, $0) }, callback) fetchArticlesAsync({ self.fetchStarredArticles(webFeedIDs, $0) }, completion)
} }
private func fetchStarredArticles(_ webFeedIDs: Set<String>, _ database: FMDatabase) -> Set<Article> { private func fetchStarredArticles(_ webFeedIDs: Set<String>, _ database: FMDatabase) -> Set<Article> {
@ -184,12 +184,12 @@ final class ArticlesTable: DatabaseTable {
return articles return articles
} }
func fetchArticlesMatchingAsync(_ searchString: String, _ webFeedIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { func fetchArticlesMatchingAsync(_ searchString: String, _ webFeedIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
fetchArticlesAsync({ self.fetchArticlesMatching(searchString, webFeedIDs, $0) }, callback) fetchArticlesAsync({ self.fetchArticlesMatching(searchString, webFeedIDs, $0) }, completion)
} }
func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set<String>, _ callback: @escaping ArticleSetBlock) { func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set<String>, _ completion: @escaping ArticleSetBlock) {
fetchArticlesAsync({ self.fetchArticlesMatchingWithArticleIDs(searchString, articleIDs, $0) }, callback) fetchArticlesAsync({ self.fetchArticlesMatchingWithArticleIDs(searchString, articleIDs, $0) }, completion)
} }
private func fetchArticlesMatching(_ searchString: String, _ webFeedIDs: Set<String>, _ database: FMDatabase) -> Set<Article> { private func fetchArticlesMatching(_ searchString: String, _ webFeedIDs: Set<String>, _ database: FMDatabase) -> Set<Article> {
@ -311,9 +311,9 @@ final class ArticlesTable: DatabaseTable {
} }
} }
func fetchStatuses(_ articleIDs: Set<String>, _ createIfNeeded: Bool, _ callback: @escaping (Set<ArticleStatus>?) -> Void) { func fetchStatuses(_ articleIDs: Set<String>, _ createIfNeeded: Bool, _ completion: @escaping (Set<ArticleStatus>?) -> Void) {
guard !queue.isSuspended else { guard !queue.isSuspended else {
callback(nil) completion(nil)
return return
} }
@ -327,7 +327,7 @@ final class ArticlesTable: DatabaseTable {
} }
let statuses = Set(statusesDictionary.values) let statuses = Set(statusesDictionary.values)
DispatchQueue.main.async { DispatchQueue.main.async {
callback(statuses) completion(statuses)
} }
} }
} }
@ -357,11 +357,11 @@ final class ArticlesTable: DatabaseTable {
} }
} }
func fetchUnreadCount(_ webFeedIDs: Set<String>, _ since: Date, _ callback: @escaping (Int) -> Void) { func fetchUnreadCount(_ webFeedIDs: Set<String>, _ since: Date, _ completion: @escaping (Int) -> Void) {
// Get unread count for today, for instance. // Get unread count for today, for instance.
if webFeedIDs.isEmpty || queue.isSuspended { if webFeedIDs.isEmpty || queue.isSuspended {
callback(0) completion(0)
return return
} }
@ -377,7 +377,7 @@ final class ArticlesTable: DatabaseTable {
let unreadCount = self.numberWithSQLAndParameters(sql, parameters, in: database) let unreadCount = self.numberWithSQLAndParameters(sql, parameters, in: database)
DispatchQueue.main.async { DispatchQueue.main.async {
callback(unreadCount) completion(unreadCount)
} }
} }
} }
@ -416,9 +416,9 @@ final class ArticlesTable: DatabaseTable {
} }
} }
func fetchStarredAndUnreadCount(_ webFeedIDs: Set<String>, _ callback: @escaping (Int) -> Void) { func fetchStarredAndUnreadCount(_ webFeedIDs: Set<String>, _ completion: @escaping (Int) -> Void) {
if webFeedIDs.isEmpty || queue.isSuspended { if webFeedIDs.isEmpty || queue.isSuspended {
callback(0) completion(0)
return return
} }
@ -430,19 +430,19 @@ final class ArticlesTable: DatabaseTable {
let unreadCount = self.numberWithSQLAndParameters(sql, parameters, in: database) let unreadCount = self.numberWithSQLAndParameters(sql, parameters, in: database)
DispatchQueue.main.async { DispatchQueue.main.async {
callback(unreadCount) completion(unreadCount)
} }
} }
} }
// MARK: - Statuses // MARK: - Statuses
func fetchUnreadArticleIDsAsync(_ webFeedIDs: Set<String>, _ callback: @escaping (Set<String>) -> Void) { func fetchUnreadArticleIDsAsync(_ webFeedIDs: Set<String>, _ completion: @escaping (Set<String>) -> Void) {
fetchArticleIDsAsync(.read, false, webFeedIDs, callback) fetchArticleIDsAsync(.read, false, webFeedIDs, completion)
} }
func fetchStarredArticleIDsAsync(_ webFeedIDs: Set<String>, _ callback: @escaping (Set<String>) -> Void) { func fetchStarredArticleIDsAsync(_ webFeedIDs: Set<String>, _ completion: @escaping (Set<String>) -> Void) {
fetchArticleIDsAsync(.starred, true, webFeedIDs, callback) fetchArticleIDsAsync(.starred, true, webFeedIDs, completion)
} }
func fetchStarredArticleIDs() -> Set<String> { func fetchStarredArticleIDs() -> Set<String> {
@ -541,15 +541,15 @@ private extension ArticlesTable {
return articles return articles
} }
private func fetchArticlesAsync(_ fetchMethod: @escaping ArticlesFetchMethod, _ callback: @escaping ArticleSetBlock) { private func fetchArticlesAsync(_ fetchMethod: @escaping ArticlesFetchMethod, _ completion: @escaping ArticleSetBlock) {
guard !queue.isSuspended else { guard !queue.isSuspended else {
callback(Set<Article>()) completion(Set<Article>())
return return
} }
queue.runInDatabase { (database) in queue.runInDatabase { (database) in
let articles = fetchMethod(database) let articles = fetchMethod(database)
DispatchQueue.main.async { DispatchQueue.main.async {
callback(articles) completion(articles)
} }
} }
} }
@ -702,9 +702,9 @@ private extension ArticlesTable {
return articlesWithResultSet(resultSet, database) return articlesWithResultSet(resultSet, database)
} }
func fetchArticleIDsAsync(_ statusKey: ArticleStatus.Key, _ value: Bool, _ webFeedIDs: Set<String>, _ callback: @escaping (Set<String>) -> Void) { func fetchArticleIDsAsync(_ statusKey: ArticleStatus.Key, _ value: Bool, _ webFeedIDs: Set<String>, _ completion: @escaping (Set<String>) -> Void) {
guard !queue.isSuspended && !webFeedIDs.isEmpty else { guard !queue.isSuspended && !webFeedIDs.isEmpty else {
callback(Set<String>()) completion(Set<String>())
return return
} }
queue.runInDatabase { database in queue.runInDatabase { database in
@ -720,14 +720,14 @@ private extension ArticlesTable {
guard let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) else { guard let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) else {
DispatchQueue.main.async { DispatchQueue.main.async {
callback(Set<String>()) completion(Set<String>())
} }
return return
} }
let articleIDs = resultSet.mapToSet{ $0.string(forColumnIndex: 0) } let articleIDs = resultSet.mapToSet{ $0.string(forColumnIndex: 0) }
DispatchQueue.main.async { DispatchQueue.main.async {
callback(articleIDs) completion(articleIDs)
} }
} }
} }

View File

@ -58,8 +58,8 @@ final class DetailViewController: NSViewController, WKUIDelegate {
currentWebViewController = webViewController(for: mode) currentWebViewController = webViewController(for: mode)
} }
func canScrollDown(_ callback: @escaping (Bool) -> Void) { func canScrollDown(_ completion: @escaping (Bool) -> Void) {
currentWebViewController.canScrollDown(callback) currentWebViewController.canScrollDown(completion)
} }
override func scrollPageDown(_ sender: Any?) { override func scrollPageDown(_ sender: Any?) {

View File

@ -127,9 +127,9 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
// MARK: Scrolling // MARK: Scrolling
func canScrollDown(_ callback: @escaping (Bool) -> Void) { func canScrollDown(_ completion: @escaping (Bool) -> Void) {
fetchScrollInfo { (scrollInfo) in fetchScrollInfo { (scrollInfo) in
callback(scrollInfo?.canScrollDown ?? false) completion(scrollInfo?.canScrollDown ?? false)
} }
} }
@ -227,7 +227,7 @@ private extension DetailWebViewController {
webView.evaluateJavaScript(render) webView.evaluateJavaScript(render)
} }
func fetchScrollInfo(_ callback: @escaping (ScrollInfo?) -> Void) { func fetchScrollInfo(_ completion: @escaping (ScrollInfo?) -> Void) {
var javascriptString = "var x = {contentHeight: document.body.scrollHeight, offsetY: document.body.scrollTop}; x" var javascriptString = "var x = {contentHeight: document.body.scrollHeight, offsetY: document.body.scrollTop}; x"
if #available(macOS 10.15, *) { if #available(macOS 10.15, *) {
javascriptString = "var x = {contentHeight: document.body.scrollHeight, offsetY: window.pageYOffset}; x" javascriptString = "var x = {contentHeight: document.body.scrollHeight, offsetY: window.pageYOffset}; x"
@ -235,16 +235,16 @@ private extension DetailWebViewController {
webView.evaluateJavaScript(javascriptString) { (info, error) in webView.evaluateJavaScript(javascriptString) { (info, error) in
guard let info = info as? [String: Any] else { guard let info = info as? [String: Any] else {
callback(nil) completion(nil)
return return
} }
guard let contentHeight = info["contentHeight"] as? CGFloat, let offsetY = info["offsetY"] as? CGFloat else { guard let contentHeight = info["contentHeight"] as? CGFloat, let offsetY = info["offsetY"] as? CGFloat else {
callback(nil) completion(nil)
return return
} }
let scrollInfo = ScrollInfo(contentHeight: contentHeight, viewHeight: self.webView.frame.height, offsetY: offsetY) let scrollInfo = ScrollInfo(contentHeight: contentHeight, viewHeight: self.webView.frame.height, offsetY: offsetY)
callback(scrollInfo) completion(scrollInfo)
} }
} }

View File

@ -595,19 +595,19 @@ private extension SidebarViewController {
return rowView.view(atColumn: 0) as? SidebarCell return rowView.view(atColumn: 0) as? SidebarCell
} }
func applyToAvailableCells(_ callback: (SidebarCell, Node) -> Void) { func applyToAvailableCells(_ completion: (SidebarCell, Node) -> Void) {
outlineView.enumerateAvailableRowViews { (rowView: NSTableRowView, row: Int) -> Void in outlineView.enumerateAvailableRowViews { (rowView: NSTableRowView, row: Int) -> Void in
guard let cell = cellForRowView(rowView), let node = nodeForRow(row) else { guard let cell = cellForRowView(rowView), let node = nodeForRow(row) else {
return return
} }
callback(cell, node) completion(cell, node)
} }
} }
func applyToCellsForRepresentedObject(_ representedObject: AnyObject, _ callback: (SidebarCell, Node) -> Void) { func applyToCellsForRepresentedObject(_ representedObject: AnyObject, _ completion: (SidebarCell, Node) -> Void) {
applyToAvailableCells { (cell, node) in applyToAvailableCells { (cell, node) in
if node.representsSidebarObject(representedObject) { if node.representsSidebarObject(representedObject) {
callback(cell, node) completion(cell, node)
} }
} }
} }

View File

@ -1027,7 +1027,7 @@ private extension TimelineViewController {
return fetchedArticles return fetchedArticles
} }
func fetchUnsortedArticlesAsync(for representedObjects: [Any], callback: @escaping ArticleSetBlock) { func fetchUnsortedArticlesAsync(for representedObjects: [Any], completion: @escaping ArticleSetBlock) {
// The callback will *not* be called if the fetch is no longer relevant that is, // The callback will *not* be called if the fetch is no longer relevant that is,
// if its been superseded by a newer fetch, or the timeline was emptied, etc., it wont get called. // if its been superseded by a newer fetch, or the timeline was emptied, etc., it wont get called.
precondition(Thread.isMainThread) precondition(Thread.isMainThread)
@ -1038,7 +1038,7 @@ private extension TimelineViewController {
guard !operation.isCanceled, let strongSelf = self, operation.id == strongSelf.fetchSerialNumber else { guard !operation.isCanceled, let strongSelf = self, operation.id == strongSelf.fetchSerialNumber else {
return return
} }
callback(articles) completion(articles)
} }
fetchRequestQueue.add(fetchOperation) fetchRequestQueue.add(fetchOperation)
} }

View File

@ -13,15 +13,15 @@ import RSParser
struct FaviconURLFinder { struct FaviconURLFinder {
static func findFaviconURLs(_ homePageURL: String, _ callback: @escaping ([String]?) -> Void) { static func findFaviconURLs(_ homePageURL: String, _ completion: @escaping ([String]?) -> Void) {
guard let _ = URL(string: homePageURL) else { guard let _ = URL(string: homePageURL) else {
callback(nil) completion(nil)
return return
} }
HTMLMetadataDownloader.downloadMetadata(for: homePageURL) { (htmlMetadata) in HTMLMetadataDownloader.downloadMetadata(for: homePageURL) { (htmlMetadata) in
callback(htmlMetadata?.faviconLinks) completion(htmlMetadata?.faviconLinks)
} }
} }
} }

View File

@ -93,22 +93,22 @@ private extension SingleFaviconDownloader {
} }
} }
func readFromDisk(_ callback: @escaping (RSImage?) -> Void) { func readFromDisk(_ completion: @escaping (RSImage?) -> Void) {
guard diskStatus != .notOnDisk else { guard diskStatus != .notOnDisk else {
callback(nil) completion(nil)
return return
} }
queue.async { queue.async {
if let data = self.diskCache[self.diskKey], !data.isEmpty { if let data = self.diskCache[self.diskKey], !data.isEmpty {
RSImage.rs_image(with: data, imageResultBlock: callback) RSImage.rs_image(with: data, imageResultBlock: completion)
return return
} }
DispatchQueue.main.async { DispatchQueue.main.async {
callback(nil) completion(nil)
} }
} }
} }
@ -127,10 +127,10 @@ private extension SingleFaviconDownloader {
} }
} }
func downloadFavicon(_ callback: @escaping (RSImage?) -> Void) { func downloadFavicon(_ completion: @escaping (RSImage?) -> Void) {
guard let url = URL(string: faviconURL) else { guard let url = URL(string: faviconURL) else {
callback(nil) completion(nil)
return return
} }
@ -138,7 +138,7 @@ private extension SingleFaviconDownloader {
if let data = data, !data.isEmpty, let response = response, response.statusIsOK, error == nil { if let data = data, !data.isEmpty, let response = response, response.statusIsOK, error == nil {
self.saveToDisk(data) self.saveToDisk(data)
RSImage.rs_image(with: data, imageResultBlock: callback) RSImage.rs_image(with: data, imageResultBlock: completion)
return return
} }
@ -146,7 +146,7 @@ private extension SingleFaviconDownloader {
appDelegate.logMessage("Error downloading favicon at \(url): \(error)", type: .warning) appDelegate.logMessage("Error downloading favicon at \(url): \(error)", type: .warning)
} }
callback(nil) completion(nil)
} }
} }

View File

@ -14,9 +14,9 @@ struct HTMLMetadataDownloader {
static let serialDispatchQueue = DispatchQueue(label: "HTMLMetadataDownloader") static let serialDispatchQueue = DispatchQueue(label: "HTMLMetadataDownloader")
static func downloadMetadata(for url: String, _ callback: @escaping (RSHTMLMetadata?) -> Void) { static func downloadMetadata(for url: String, _ completion: @escaping (RSHTMLMetadata?) -> Void) {
guard let actualURL = URL(string: url) else { guard let actualURL = URL(string: url) else {
callback(nil) completion(nil)
return return
} }
@ -24,7 +24,7 @@ struct HTMLMetadataDownloader {
if let data = data, !data.isEmpty, let response = response, response.statusIsOK, error == nil { if let data = data, !data.isEmpty, let response = response, response.statusIsOK, error == nil {
let urlToUse = response.url ?? actualURL let urlToUse = response.url ?? actualURL
let parserData = ParserData(url: urlToUse.absoluteString, data: data) let parserData = ParserData(url: urlToUse.absoluteString, data: data)
parseMetadata(with: parserData, callback) parseMetadata(with: parserData, completion)
return return
} }
@ -32,15 +32,15 @@ struct HTMLMetadataDownloader {
appDelegate.logMessage("Error downloading metadata at \(url): \(error)", type: .warning) appDelegate.logMessage("Error downloading metadata at \(url): \(error)", type: .warning)
} }
callback(nil) completion(nil)
} }
} }
private static func parseMetadata(with parserData: ParserData, _ callback: @escaping (RSHTMLMetadata?) -> Void) { private static func parseMetadata(with parserData: ParserData, _ completion: @escaping (RSHTMLMetadata?) -> Void) {
serialDispatchQueue.async { serialDispatchQueue.async {
let htmlMetadata = RSHTMLMetadataParser.htmlMetadata(with: parserData) let htmlMetadata = RSHTMLMetadataParser.htmlMetadata(with: parserData)
DispatchQueue.main.async { DispatchQueue.main.async {
callback(htmlMetadata) completion(htmlMetadata)
} }
} }
} }

View File

@ -76,27 +76,27 @@ private extension ImageDownloader {
} }
} }
func readFromDisk(_ url: String, _ callback: @escaping (Data?) -> Void) { func readFromDisk(_ url: String, _ completion: @escaping (Data?) -> Void) {
queue.async { queue.async {
if let data = self.diskCache[self.diskKey(url)], !data.isEmpty { if let data = self.diskCache[self.diskKey(url)], !data.isEmpty {
DispatchQueue.main.async { DispatchQueue.main.async {
callback(data) completion(data)
} }
return return
} }
DispatchQueue.main.async { DispatchQueue.main.async {
callback(nil) completion(nil)
} }
} }
} }
func downloadImage(_ url: String, _ callback: @escaping (Data?) -> Void) { func downloadImage(_ url: String, _ completion: @escaping (Data?) -> Void) {
guard let imageURL = URL(string: url) else { guard let imageURL = URL(string: url) else {
callback(nil) completion(nil)
return return
} }
@ -104,7 +104,7 @@ private extension ImageDownloader {
if let data = data, !data.isEmpty, let response = response, response.statusIsOK, error == nil { if let data = data, !data.isEmpty, let response = response, response.statusIsOK, error == nil {
self.saveToDisk(url, data) self.saveToDisk(url, data)
callback(data) completion(data)
return return
} }
@ -115,7 +115,7 @@ private extension ImageDownloader {
appDelegate.logMessage("Error downloading image at \(url): \(error)", type: .warning) appDelegate.logMessage("Error downloading image at \(url): \(error)", type: .warning)
} }
callback(nil) completion(nil)
} }
} }

View File

@ -31,7 +31,7 @@ struct SearchFeedDelegate: SmartFeedDelegate {
self.fetchType = .search(searchString) self.fetchType = .search(searchString)
} }
func fetchUnreadCount(for: Account, callback: @escaping (Int) -> Void) { func fetchUnreadCount(for: Account, completion: @escaping (Int) -> Void) {
// TODO: after 5.0 // TODO: after 5.0
} }
} }

View File

@ -31,7 +31,7 @@ struct SearchTimelineFeedDelegate: SmartFeedDelegate {
self.fetchType = .searchWithArticleIDs(searchString, articleIDs) self.fetchType = .searchWithArticleIDs(searchString, articleIDs)
} }
func fetchUnreadCount(for: Account, callback: @escaping (Int) -> Void) { func fetchUnreadCount(for: Account, completion: @escaping (Int) -> Void) {
// TODO: after 5.0 // TODO: after 5.0
} }
} }

View File

@ -84,16 +84,16 @@ extension SmartFeed: ArticleFetcher {
return delegate.fetchArticles() return delegate.fetchArticles()
} }
func fetchArticlesAsync(_ callback: @escaping ArticleSetBlock) { func fetchArticlesAsync(_ completion: @escaping ArticleSetBlock) {
delegate.fetchArticlesAsync(callback) delegate.fetchArticlesAsync(completion)
} }
func fetchUnreadArticles() -> Set<Article> { func fetchUnreadArticles() -> Set<Article> {
return delegate.fetchUnreadArticles() return delegate.fetchUnreadArticles()
} }
func fetchUnreadArticlesAsync(_ callback: @escaping ArticleSetBlock) { func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetBlock) {
delegate.fetchUnreadArticlesAsync(callback) delegate.fetchUnreadArticlesAsync(completion)
} }
} }

View File

@ -13,7 +13,7 @@ import RSCore
protocol SmartFeedDelegate: FeedIdentifiable, DisplayNameProvider, ArticleFetcher, SmallIconProvider { protocol SmartFeedDelegate: FeedIdentifiable, DisplayNameProvider, ArticleFetcher, SmallIconProvider {
var fetchType: FetchType { get } var fetchType: FetchType { get }
func fetchUnreadCount(for: Account, callback: @escaping (Int) -> Void) func fetchUnreadCount(for: Account, completion: @escaping (Int) -> Void)
} }
extension SmartFeedDelegate { extension SmartFeedDelegate {
@ -22,15 +22,15 @@ extension SmartFeedDelegate {
return AccountManager.shared.fetchArticles(fetchType) return AccountManager.shared.fetchArticles(fetchType)
} }
func fetchArticlesAsync(_ callback: @escaping ArticleSetBlock) { func fetchArticlesAsync(_ completion: @escaping ArticleSetBlock) {
AccountManager.shared.fetchArticlesAsync(fetchType, callback) AccountManager.shared.fetchArticlesAsync(fetchType, completion)
} }
func fetchUnreadArticles() -> Set<Article> { func fetchUnreadArticles() -> Set<Article> {
return fetchArticles().unreadArticles() return fetchArticles().unreadArticles()
} }
func fetchUnreadArticlesAsync(_ callback: @escaping ArticleSetBlock) { func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetBlock) {
fetchArticlesAsync{ callback($0.unreadArticles()) } fetchArticlesAsync{ completion($0.unreadArticles()) }
} }
} }

View File

@ -23,7 +23,7 @@ struct StarredFeedDelegate: SmartFeedDelegate {
let fetchType: FetchType = .starred let fetchType: FetchType = .starred
var smallIcon: IconImage? = AppAssets.starredFeedImage var smallIcon: IconImage? = AppAssets.starredFeedImage
func fetchUnreadCount(for account: Account, callback: @escaping (Int) -> Void) { func fetchUnreadCount(for account: Account, completion: @escaping (Int) -> Void) {
account.fetchUnreadCountForStarredArticles(callback) account.fetchUnreadCountForStarredArticles(completion)
} }
} }

View File

@ -21,8 +21,8 @@ struct TodayFeedDelegate: SmartFeedDelegate {
let fetchType = FetchType.today let fetchType = FetchType.today
var smallIcon: IconImage? = AppAssets.todayFeedImage var smallIcon: IconImage? = AppAssets.todayFeedImage
func fetchUnreadCount(for account: Account, callback: @escaping (Int) -> Void) { func fetchUnreadCount(for account: Account, completion: @escaping (Int) -> Void) {
account.fetchUnreadCountForToday(callback) account.fetchUnreadCountForToday(completion)
} }
} }

View File

@ -65,15 +65,15 @@ extension UnreadFeed: ArticleFetcher {
return fetchUnreadArticles() return fetchUnreadArticles()
} }
func fetchArticlesAsync(_ callback: @escaping ArticleSetBlock) { func fetchArticlesAsync(_ completion: @escaping ArticleSetBlock) {
fetchUnreadArticlesAsync(callback) fetchUnreadArticlesAsync(completion)
} }
func fetchUnreadArticles() -> Set<Article> { func fetchUnreadArticles() -> Set<Article> {
return AccountManager.shared.fetchArticles(fetchType) return AccountManager.shared.fetchArticles(fetchType)
} }
func fetchUnreadArticlesAsync(_ callback: @escaping ArticleSetBlock) { func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetBlock) {
AccountManager.shared.fetchArticlesAsync(fetchType, callback) AccountManager.shared.fetchArticlesAsync(fetchType, completion)
} }
} }

View File

@ -764,20 +764,20 @@ private extension MasterFeedViewController {
applyToCellsForRepresentedObject(representedObject, configure) applyToCellsForRepresentedObject(representedObject, configure)
} }
func applyToCellsForRepresentedObject(_ representedObject: AnyObject, _ callback: (MasterFeedTableViewCell, Node) -> Void) { func applyToCellsForRepresentedObject(_ representedObject: AnyObject, _ completion: (MasterFeedTableViewCell, Node) -> Void) {
applyToAvailableCells { (cell, node) in applyToAvailableCells { (cell, node) in
if node.representedObject === representedObject { if node.representedObject === representedObject {
callback(cell, node) completion(cell, node)
} }
} }
} }
func applyToAvailableCells(_ callback: (MasterFeedTableViewCell, Node) -> Void) { func applyToAvailableCells(_ completion: (MasterFeedTableViewCell, Node) -> Void) {
tableView.visibleCells.forEach { cell in tableView.visibleCells.forEach { cell in
guard let indexPath = tableView.indexPath(for: cell), let node = dataSource.itemIdentifier(for: indexPath) else { guard let indexPath = tableView.indexPath(for: cell), let node = dataSource.itemIdentifier(for: indexPath) else {
return return
} }
callback(cell as! MasterFeedTableViewCell, node) completion(cell as! MasterFeedTableViewCell, node)
} }
} }

View File

@ -1630,7 +1630,7 @@ private extension SceneCoordinator {
} }
func fetchUnsortedArticlesAsync(for representedObjects: [Any], callback: @escaping ArticleSetBlock) { func fetchUnsortedArticlesAsync(for representedObjects: [Any], completion: @escaping ArticleSetBlock) {
// The callback will *not* be called if the fetch is no longer relevant that is, // The callback will *not* be called if the fetch is no longer relevant that is,
// if its been superseded by a newer fetch, or the timeline was emptied, etc., it wont get called. // if its been superseded by a newer fetch, or the timeline was emptied, etc., it wont get called.
precondition(Thread.isMainThread) precondition(Thread.isMainThread)
@ -1641,7 +1641,7 @@ private extension SceneCoordinator {
guard !operation.isCanceled, let strongSelf = self, operation.id == strongSelf.fetchSerialNumber else { guard !operation.isCanceled, let strongSelf = self, operation.id == strongSelf.fetchSerialNumber else {
return return
} }
callback(articles) completion(articles)
} }
fetchRequestQueue.add(fetchOperation) fetchRequestQueue.add(fetchOperation)

@ -1 +1 @@
Subproject commit b2ad9272e8003b0aba3c8c961239663ac501f00b Subproject commit 8a574c7dc24156d9d01c6c9fe7d4c9e099c54a96

@ -1 +1 @@
Subproject commit 81c400a7665309a08414bf43ca5161d90d072501 Subproject commit 9e5f5d644c1291daf516b9466cb23592374f8e10

@ -1 +1 @@
Subproject commit b2dd50f1ff2a64c09a543d00bc35c8a66c1fc2b6 Subproject commit e513062972cd8097179ed39999f327ad29c8a4e1