From 1066ca2720266fe2b92aa433739aae418cf88aec Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 10 Jun 2026 16:59:28 -0700 Subject: [PATCH] Continue post-DatabaseResult simplification. --- Mac/AppDelegate.swift | 3 +- ...idebarViewController+ContextualMenus.swift | 5 +- .../Sidebar/SidebarViewController.swift | 2 +- ...melineViewController+ContextualMenus.swift | 3 +- .../Timeline/TimelineViewController.swift | 10 +- Mac/Scripting/Feed+Scriptability.swift | 4 +- Mac/Scripting/Folder+Scriptability.swift | 6 +- Modules/Account/Sources/Account/Account.swift | 72 +++++------ .../Sources/Account/AccountManager.swift | 18 ++- .../Sources/Account/ArticleFetcher.swift | 40 +++--- .../CloudKit/CloudKitAccountDelegate.swift | 3 +- .../CloudKitSendStatusOperation.swift | 10 +- .../Account/SingleArticleFetcher.swift | 16 +-- .../ArticlesDatabase/ArticlesDatabase.swift | 117 ++++++++---------- .../ArticlesDatabase/ArticlesTable.swift | 18 +-- .../ArticlesDatabase/StatusesTable.swift | 6 +- Shared/Activity/ActivityManager.swift | 9 +- Shared/SmartFeeds/SmartFeed.swift | 16 +-- Shared/SmartFeeds/SmartFeedDelegate.swift | 16 +-- Shared/SmartFeeds/UnreadFeed.swift | 16 +-- Shared/Timeline/FetchRequestOperation.swift | 30 ++--- Shared/Widget/WidgetDataEncoder.swift | 22 ++-- iOS/AppDelegate.swift | 7 +- .../MainFeedCollectionViewController.swift | 17 +-- .../MainTimelineModernViewController.swift | 8 +- 25 files changed, 215 insertions(+), 259 deletions(-) diff --git a/Mac/AppDelegate.swift b/Mac/AppDelegate.swift index 2499f3f16..cd94cb6e3 100644 --- a/Mac/AppDelegate.swift +++ b/Mac/AppDelegate.swift @@ -1155,7 +1155,8 @@ private extension AppDelegate { return } - guard let singleArticleSet = try? account.fetchArticles(.articleIDs([articleID])) else { + let singleArticleSet = account.fetchArticles(.articleIDs([articleID])) + guard singleArticleSet.count > 0 else { assertionFailure("Expected article with \(articleID)") Self.logger.error("No article with articleID found \(articleID) from status notification") return diff --git a/Mac/MainWindow/Sidebar/SidebarViewController+ContextualMenus.swift b/Mac/MainWindow/Sidebar/SidebarViewController+ContextualMenus.swift index 1fc96befc..685f0e24b 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController+ContextualMenus.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController+ContextualMenus.swift @@ -346,9 +346,8 @@ private extension SidebarViewController { var articles = Set
() for object in objects { if let articleFetcher = object as? ArticleFetcher { - if let unreadArticles = try? articleFetcher.fetchUnreadArticles() { - articles.formUnion(unreadArticles) - } + let unreadArticles = articleFetcher.fetchUnreadArticles() + articles.formUnion(unreadArticles) } } return articles diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index 16d008245..70337a415 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -299,7 +299,7 @@ extension Notification.Name { guard outlineView.clickedRow == outlineView.selectedRow else { return } - if AppDefaults.shared.feedDoubleClickMarkAsRead, let articles = try? singleSelectedFeed?.fetchUnreadArticles() { + if AppDefaults.shared.feedDoubleClickMarkAsRead, let articles = singleSelectedFeed?.fetchUnreadArticles() { if let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: Array(articles), markingRead: true, undoManager: undoManager) { runCommand(markReadCommand) } diff --git a/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift b/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift index 8d31fbfd0..9bf327ac3 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController+ContextualMenus.swift @@ -77,7 +77,8 @@ extension TimelineViewController { return } - guard let unreadArticles = try? feed.fetchUnreadArticles(), !unreadArticles.isEmpty else { + let unreadArticles = feed.fetchUnreadArticles() + guard !unreadArticles.isEmpty else { return } guard let undoManager, let markReadCommand = MarkStatusCommand( diff --git a/Mac/MainWindow/Timeline/TimelineViewController.swift b/Mac/MainWindow/Timeline/TimelineViewController.swift index 983adb457..357565607 100644 --- a/Mac/MainWindow/Timeline/TimelineViewController.swift +++ b/Mac/MainWindow/Timeline/TimelineViewController.swift @@ -1229,13 +1229,11 @@ private extension TimelineViewController { var fetchedArticles = Set
() for fetchers in fetchers { if (fetchers as? SidebarItem)?.readFiltered(readFilterEnabledTable: readFilterEnabledTable) ?? true { - if let articles = try? fetchers.fetchUnreadArticles() { - fetchedArticles.formUnion(articles) - } + let articles = fetchers.fetchUnreadArticles() + fetchedArticles.formUnion(articles) } else { - if let articles = try? fetchers.fetchArticles() { - fetchedArticles.formUnion(articles) - } + let articles = fetchers.fetchArticles() + fetchedArticles.formUnion(articles) } } return fetchedArticles diff --git a/Mac/Scripting/Feed+Scriptability.swift b/Mac/Scripting/Feed+Scriptability.swift index 23e6396a2..0c3dc2d5d 100644 --- a/Mac/Scripting/Feed+Scriptability.swift +++ b/Mac/Scripting/Feed+Scriptability.swift @@ -193,7 +193,7 @@ import Articles @objc(articles) var articles: NSArray { - let feedArticles = (try? feed.fetchArticles()) ?? Set
() + let feedArticles = feed.fetchArticles() // the articles are a set, use the sorting algorithm from the viewer let sortedArticles = feedArticles.sorted(by: { return $0.logicalDatePublished > $1.logicalDatePublished @@ -203,7 +203,7 @@ import Articles @objc(valueInArticlesWithUniqueID:) func valueInArticles(withUniqueID id: String) -> ScriptableArticle? { - let articles = (try? feed.fetchArticles()) ?? Set
() + let articles = feed.fetchArticles() guard let article = articles.first(where: {$0.uniqueID == id}) else { return nil } diff --git a/Mac/Scripting/Folder+Scriptability.swift b/Mac/Scripting/Folder+Scriptability.swift index 7dcaf9896..965239510 100644 --- a/Mac/Scripting/Folder+Scriptability.swift +++ b/Mac/Scripting/Folder+Scriptability.swift @@ -106,7 +106,7 @@ import RSCore var articles: NSArray { let feeds = Array(folder.topLevelFeeds) let allArticles = feeds.flatMap { feed in - (try? feed.fetchArticles()) ?? Set
() + feed.fetchArticles() } // Sort articles by logical date published like Feed does let sortedArticles = allArticles.sorted(by: { @@ -119,7 +119,7 @@ import RSCore func countOfArticles() -> Int { let feeds = Array(folder.topLevelFeeds) return feeds.reduce(0) { count, feed in - let feedArticles = (try? feed.fetchArticles()) ?? Set
() + let feedArticles = feed.fetchArticles() return count + feedArticles.count } } @@ -128,7 +128,7 @@ import RSCore func objectInArticlesAtIndex(_ index: Int) -> ScriptableArticle? { let feeds = Array(folder.topLevelFeeds) let allArticles = feeds.flatMap { feed in - (try? feed.fetchArticles()) ?? Set
() + feed.fetchArticles() } let sortedArticles = allArticles.sorted(by: { return $0.logicalDatePublished > $1.logicalDatePublished diff --git a/Modules/Account/Sources/Account/Account.swift b/Modules/Account/Sources/Account/Account.swift index a4dc740ac..7b40a5ea8 100644 --- a/Modules/Account/Sources/Account/Account.swift +++ b/Modules/Account/Sources/Account/Account.swift @@ -812,7 +812,7 @@ public enum FetchType { // MARK: - Fetching Articles - public func fetchArticles(_ fetchType: FetchType) throws -> Set
{ + public func fetchArticles(_ fetchType: FetchType) -> Set
{ switch fetchType { case .starred(let limit): return _fetchStarredArticles(limit: limit) @@ -831,34 +831,34 @@ public enum FetchType { case .articleIDs(let articleIDs): return _fetchArticles(articleIDs: articleIDs) case .search(let searchString): - return try _fetchArticlesMatching(searchString: searchString) + return _fetchArticlesMatching(searchString: searchString) case .searchWithArticleIDs(let searchString, let articleIDs): - return try _fetchArticlesMatchingWithArticleIDs(searchString: searchString, articleIDs: articleIDs) + return _fetchArticlesMatchingWithArticleIDs(searchString: searchString, articleIDs: articleIDs) } } - public func fetchArticlesAsync(_ fetchType: FetchType) async throws -> Set
{ + public func fetchArticlesAsync(_ fetchType: FetchType) async -> Set
{ switch fetchType { case .starred(let limit): - return try await _fetchStarredArticlesAsync(limit: limit) + return await _fetchStarredArticlesAsync(limit: limit) case .unread(let limit): - return try await _fetchUnreadArticlesAsync(limit: limit) + return await _fetchUnreadArticlesAsync(limit: limit) case .today(let limit): - return try await _fetchTodayArticlesAsync(limit: limit) + return await _fetchTodayArticlesAsync(limit: limit) case .folder(let folder, let readFilter): if readFilter { - return try await _fetchUnreadArticlesAsync(container: folder) + return await _fetchUnreadArticlesAsync(container: folder) } else { - return try await _fetchArticlesAsync(container: folder) + return await _fetchArticlesAsync(container: folder) } case .feed(let feed): - return try await _fetchArticlesAsync(feed: feed) + return await _fetchArticlesAsync(feed: feed) case .articleIDs(let articleIDs): - return try await _fetchArticlesAsync(articleIDs: articleIDs) + return await _fetchArticlesAsync(articleIDs: articleIDs) case .search(let searchString): - return try await _fetchArticlesMatchingAsync(searchString: searchString) + return await _fetchArticlesMatchingAsync(searchString: searchString) case .searchWithArticleIDs(let searchString, let articleIDs): - return try await _fetchArticlesMatchingWithArticleIDsAsync(searchString: searchString, articleIDs: articleIDs) + return await _fetchArticlesMatchingWithArticleIDsAsync(searchString: searchString, articleIDs: articleIDs) } } @@ -1133,7 +1133,7 @@ public enum FetchType { public func debugRunSearch() { #if DEBUG let t1 = Date() - let articles = try! _fetchArticlesMatching(searchString: "Brent NetNewsWire") + let articles = _fetchArticlesMatching(searchString: "Brent NetNewsWire") let t2 = Date() print(t2.timeIntervalSince(t1)) print(articles.count) @@ -1207,8 +1207,8 @@ private extension Account { database.fetchStarredArticles(feedIDs: flattenedFeedsIDs, limit: limit) } - func _fetchStarredArticlesAsync(limit: Int? = nil) async throws -> Set
{ - try await database.fetchedStarredArticlesAsync(feedIDs: flattenedFeedsIDs, limit: limit) + func _fetchStarredArticlesAsync(limit: Int? = nil) async -> Set
{ + await database.fetchedStarredArticlesAsync(feedIDs: flattenedFeedsIDs, limit: limit) } // MARK: - Account Unread Articles @@ -1217,8 +1217,8 @@ private extension Account { _fetchUnreadArticles(container: self, limit: limit) } - func _fetchUnreadArticlesAsync(limit: Int? = nil) async throws -> Set
{ - try await _fetchUnreadArticlesAsync(container: self, limit: limit) + func _fetchUnreadArticlesAsync(limit: Int? = nil) async -> Set
{ + await _fetchUnreadArticlesAsync(container: self, limit: limit) } // MARK: - Today Articles @@ -1227,8 +1227,8 @@ private extension Account { database.fetchTodayArticles(feedIDs: flattenedFeedsIDs, limit: limit) } - func _fetchTodayArticlesAsync(limit: Int? = nil) async throws -> Set
{ - try await database.fetchTodayArticlesAsync(feedIDs: flattenedFeedsIDs, limit: limit) + func _fetchTodayArticlesAsync(limit: Int? = nil) async -> Set
{ + await database.fetchTodayArticlesAsync(feedIDs: flattenedFeedsIDs, limit: limit) } // MARK: - Container Articles @@ -1240,9 +1240,9 @@ private extension Account { return articles } - func _fetchArticlesAsync(container: Container) async throws -> Set
{ + func _fetchArticlesAsync(container: Container) async -> Set
{ let feeds = container.flattenedFeeds() - let articles = try await database.fetchArticlesAsync(feedIDs: feeds.feedIDs()) + let articles = await database.fetchArticlesAsync(feedIDs: feeds.feedIDs()) validateUnreadCountsAfterFetchingUnreadArticles(feeds: feeds, articles: articles) return articles } @@ -1260,9 +1260,9 @@ private extension Account { return articles } - func _fetchUnreadArticlesAsync(container: Container, limit: Int? = nil) async throws -> Set
{ + func _fetchUnreadArticlesAsync(container: Container, limit: Int? = nil) async -> Set
{ let feeds = container.flattenedFeeds() - let articles = try await database.fetchUnreadArticlesAsync(feedIDs: feeds.feedIDs(), limit: limit) + let articles = await database.fetchUnreadArticlesAsync(feedIDs: feeds.feedIDs(), limit: limit) // We don't validate limit queries because they, by definition, won't correctly match the // complete unread state for the given container. @@ -1281,8 +1281,8 @@ private extension Account { return articles } - func _fetchArticlesAsync(feed: Feed) async throws -> Set
{ - let articles = try await database.fetchArticlesAsync(feedID: feed.feedID) + func _fetchArticlesAsync(feed: Feed) async -> Set
{ + let articles = await database.fetchArticlesAsync(feedID: feed.feedID) validateUnreadCount(feed: feed, articles: articles) return articles } @@ -1299,26 +1299,26 @@ private extension Account { database.fetchArticles(articleIDs: articleIDs) } - func _fetchArticlesAsync(articleIDs: Set) async throws -> Set
{ - try await database.fetchArticlesAsync(articleIDs: articleIDs) + func _fetchArticlesAsync(articleIDs: Set) async -> Set
{ + await database.fetchArticlesAsync(articleIDs: articleIDs) } // MARK: - Search Articles - func _fetchArticlesMatching(searchString: String) throws -> Set
{ - try database.fetchArticlesMatching(searchString: searchString, feedIDs: flattenedFeedsIDs) + func _fetchArticlesMatching(searchString: String) -> Set
{ + database.fetchArticlesMatching(searchString: searchString, feedIDs: flattenedFeedsIDs) } - func _fetchArticlesMatchingAsync(searchString: String) async throws -> Set
{ - try await database.fetchArticlesMatchingAsync(searchString: searchString, feedIDs: flattenedFeedsIDs) + func _fetchArticlesMatchingAsync(searchString: String) async -> Set
{ + await database.fetchArticlesMatchingAsync(searchString: searchString, feedIDs: flattenedFeedsIDs) } - func _fetchArticlesMatchingWithArticleIDs(searchString: String, articleIDs: Set) throws -> Set
{ - try database.fetchArticlesMatchingWithArticleIDs(searchString: searchString, articleIDs: articleIDs) + func _fetchArticlesMatchingWithArticleIDs(searchString: String, articleIDs: Set) -> Set
{ + database.fetchArticlesMatchingWithArticleIDs(searchString: searchString, articleIDs: articleIDs) } - func _fetchArticlesMatchingWithArticleIDsAsync(searchString: String, articleIDs: Set) async throws -> Set
{ - try await database.fetchArticlesMatchingWithArticleIDsAsync(searchString: searchString, articleIDs: articleIDs) + func _fetchArticlesMatchingWithArticleIDsAsync(searchString: String, articleIDs: Set) async -> Set
{ + await database.fetchArticlesMatchingWithArticleIDsAsync(searchString: searchString, articleIDs: articleIDs) } // MARK: - Unread Counts diff --git a/Modules/Account/Sources/Account/AccountManager.swift b/Modules/Account/Sources/Account/AccountManager.swift index 520c342aa..b81486d73 100644 --- a/Modules/Account/Sources/Account/AccountManager.swift +++ b/Modules/Account/Sources/Account/AccountManager.swift @@ -392,17 +392,17 @@ import ActivityLog // These fetch articles from active accounts and return a merged Set
. - public func fetchArticles(_ fetchType: FetchType) throws -> Set
{ + public func fetchArticles(_ fetchType: FetchType) -> Set
{ precondition(Thread.isMainThread) var articles = Set
() for account in activeAccounts { - articles.formUnion(try account.fetchArticles(fetchType)) + articles.formUnion(account.fetchArticles(fetchType)) } return articles } - public func fetchArticlesAsync(_ fetchType: FetchType) async throws -> Set
{ + public func fetchArticlesAsync(_ fetchType: FetchType) async -> Set
{ precondition(Thread.isMainThread) guard activeAccounts.count > 0 else { @@ -411,7 +411,7 @@ import ActivityLog var allFetchedArticles = Set
() for account in activeAccounts { - let articles = try await account.fetchArticlesAsync(fetchType) + let articles = await account.fetchArticlesAsync(fetchType) allFetchedArticles.formUnion(articles) } @@ -426,17 +426,13 @@ import ActivityLog return nil } - do { - let articles = try account.fetchArticles(.articleIDs(Set([articleID]))) - return articles.first - } catch { - return nil - } + let articles = account.fetchArticles(.articleIDs(Set([articleID]))) + return articles.first } // MARK: - Fetching Article Counts - public func fetchCountForStarredArticles() throws -> Int { + public func fetchCountForStarredArticles() -> Int { precondition(Thread.isMainThread) var count = 0 for account in activeAccounts { diff --git a/Modules/Account/Sources/Account/ArticleFetcher.swift b/Modules/Account/Sources/Account/ArticleFetcher.swift index cc5274cfa..59c87a7da 100644 --- a/Modules/Account/Sources/Account/ArticleFetcher.swift +++ b/Modules/Account/Sources/Account/ArticleFetcher.swift @@ -11,72 +11,72 @@ import Articles import ArticlesDatabase @MainActor public protocol ArticleFetcher { - func fetchArticles() throws -> Set
- func fetchArticlesAsync() async throws -> Set
- func fetchUnreadArticles() throws -> Set
- func fetchUnreadArticlesAsync() async throws -> Set
+ func fetchArticles() -> Set
+ func fetchArticlesAsync() async -> Set
+ func fetchUnreadArticles() -> Set
+ func fetchUnreadArticlesAsync() async -> Set
} extension Feed: ArticleFetcher { - public func fetchArticles() throws -> Set
{ - return try account?.fetchArticles(.feed(self)) ?? Set
() + public func fetchArticles() -> Set
{ + account?.fetchArticles(.feed(self)) ?? Set
() } - public func fetchArticlesAsync() async throws -> Set
{ + public func fetchArticlesAsync() async -> Set
{ guard let account else { assertionFailure("Expected feed.account, but got nil.") return Set
() } - return try await account.fetchArticlesAsync(.feed(self)) + return await account.fetchArticlesAsync(.feed(self)) } - public func fetchUnreadArticles() throws -> Set
{ - return try fetchArticles().unreadArticles() + public func fetchUnreadArticles() -> Set
{ + fetchArticles().unreadArticles() } - public func fetchUnreadArticlesAsync() async throws -> Set
{ + public func fetchUnreadArticlesAsync() async -> Set
{ guard let account else { assertionFailure("Expected feed.account, but got nil.") return Set
() } // TODO: fetch only unread articles rather than filtering. - let articles = try await account.fetchArticlesAsync(.feed(self)) + let articles = await account.fetchArticlesAsync(.feed(self)) return articles.unreadArticles() } } extension Folder: ArticleFetcher { - public func fetchArticles() throws -> Set
{ + public func fetchArticles() -> Set
{ guard let account else { assertionFailure("Expected folder.account, but got nil.") return Set
() } - return try account.fetchArticles(.folder(self, false)) + return account.fetchArticles(.folder(self, false)) } - public func fetchArticlesAsync() async throws -> Set
{ + public func fetchArticlesAsync() async -> Set
{ guard let account else { assertionFailure("Expected folder.account, but got nil.") return Set
() } - return try await account.fetchArticlesAsync(.folder(self, false)) + return await account.fetchArticlesAsync(.folder(self, false)) } - public func fetchUnreadArticles() throws -> Set
{ + public func fetchUnreadArticles() -> Set
{ guard let account else { assertionFailure("Expected folder.account, but got nil.") return Set
() } - return try account.fetchArticles(.folder(self, true)) + return account.fetchArticles(.folder(self, true)) } - public func fetchUnreadArticlesAsync() async throws -> Set
{ + public func fetchUnreadArticlesAsync() async -> Set
{ guard let account else { assertionFailure("Expected folder.account, but got nil.") return Set
() } - return try await account.fetchArticlesAsync(.folder(self, true)) + return await account.fetchArticlesAsync(.folder(self, true)) } } diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift index d01180cd3..782c7df58 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitAccountDelegate.swift @@ -939,12 +939,13 @@ private extension CloudKitAccountDelegate { Self.logger.debug("CloudKitAccountDelegate: \(#function, privacy: .public)") Task { do { - let articles = try await account.fetchArticlesAsync(.feed(feed)) + let articles = await account.fetchArticlesAsync(.feed(feed)) await storeArticleChanges(new: articles, updated: Set
(), deleted: Set
()) syncProgress.completeTask() _ = try await sendArticleStatus(account: account, showProgress: true) + do { try await articlesZone.fetchChangesInZone() } catch { diff --git a/Modules/Account/Sources/Account/CloudKit/CloudKitSendStatusOperation.swift b/Modules/Account/Sources/Account/CloudKit/CloudKitSendStatusOperation.swift index 2001b8e38..6d2c0366d 100644 --- a/Modules/Account/Sources/Account/CloudKit/CloudKitSendStatusOperation.swift +++ b/Modules/Account/Sources/Account/CloudKit/CloudKitSendStatusOperation.swift @@ -99,15 +99,7 @@ final class CloudKitSendStatusOperation: MainThreadOperation, @unchecked Sendabl } let articleIDs = syncStatuses.map({ $0.articleID }) - let articles: Set
- - do { - articles = try await account.fetchArticlesAsync(.articleIDs(Set(articleIDs))) - } catch { - await syncDatabase.resetSelectedForProcessing(Set(syncStatuses.map({ $0.articleID }))) - Self.logger.error("iCloud: Send article status fetch articles error: \(error.localizedDescription)") - throw error - } + let articles = await account.fetchArticlesAsync(.articleIDs(Set(articleIDs))) let syncStatusesDict = Dictionary(grouping: syncStatuses, by: { $0.articleID }) let articlesDict = articles.reduce(into: [String: Article]()) { result, article in diff --git a/Modules/Account/Sources/Account/SingleArticleFetcher.swift b/Modules/Account/Sources/Account/SingleArticleFetcher.swift index 873e42b81..e32d1ac16 100644 --- a/Modules/Account/Sources/Account/SingleArticleFetcher.swift +++ b/Modules/Account/Sources/Account/SingleArticleFetcher.swift @@ -20,19 +20,19 @@ public struct SingleArticleFetcher: ArticleFetcher { self.articleID = articleID } - public func fetchArticles() throws -> Set
{ - try account.fetchArticles(.articleIDs(Set([articleID]))) + public func fetchArticles() -> Set
{ + account.fetchArticles(.articleIDs(Set([articleID]))) } - public func fetchArticlesAsync() async throws -> Set
{ - try await account.fetchArticlesAsync(.articleIDs(Set([articleID]))) + public func fetchArticlesAsync() async -> Set
{ + await account.fetchArticlesAsync(.articleIDs(Set([articleID]))) } - public func fetchUnreadArticles() throws -> Set
{ - try account.fetchArticles(.articleIDs(Set([articleID]))) + public func fetchUnreadArticles() -> Set
{ + account.fetchArticles(.articleIDs(Set([articleID]))) } - public func fetchUnreadArticlesAsync() async throws -> Set
{ - try await account.fetchArticlesAsync(.articleIDs(Set([articleID]))) + public func fetchUnreadArticlesAsync() async -> Set
{ + await account.fetchArticlesAsync(.articleIDs(Set([articleID]))) } } diff --git a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift index 2be7eea07..c6874c951 100644 --- a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift +++ b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift @@ -153,14 +153,14 @@ public struct ArticleCounts: Sendable { } } - public func fetchArticlesMatching(searchString: String, feedIDs: Set) throws -> Set
{ + public func fetchArticlesMatching(searchString: String, feedIDs: Set) -> Set
{ Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - return try articlesTable.fetchArticlesMatching(searchString, feedIDs) + return articlesTable.fetchArticlesMatching(searchString, feedIDs) } - public func fetchArticlesMatchingWithArticleIDs(searchString: String, articleIDs: Set) throws -> Set
{ + public func fetchArticlesMatchingWithArticleIDs(searchString: String, articleIDs: Set) -> Set
{ Self.logger.debug("ArticlesDatabase: \(#function, privacy: .public) \(self.accountID, privacy: .public)") - return try articlesTable.fetchArticlesMatchingWithArticleIDs(searchString, articleIDs) + return articlesTable.fetchArticlesMatchingWithArticleIDs(searchString, articleIDs) } /// Returns a dictionary of feedID → latest article date for all feeds with articles. @@ -175,66 +175,66 @@ public struct ArticleCounts: Sendable { // MARK: - Fetching Articles Async - public func fetchArticlesAsync(feedID: String) async throws -> Set
{ - try await withCheckedThrowingContinuation { continuation in - _fetchArticlesAsync(feedID: feedID) { result in - continuation.resume(with: result) + public func fetchArticlesAsync(feedID: String) async -> Set
{ + await withCheckedContinuation { continuation in + _fetchArticlesAsync(feedID: feedID) { articles in + continuation.resume(returning: articles) } } } - public func fetchArticlesAsync(feedIDs: Set) async throws -> Set
{ - try await withCheckedThrowingContinuation { continuation in - _fetchArticlesAsync(feedIDs: feedIDs) { result in - continuation.resume(with: result) + public func fetchArticlesAsync(feedIDs: Set) async -> Set
{ + await withCheckedContinuation { continuation in + _fetchArticlesAsync(feedIDs: feedIDs) { articles in + continuation.resume(returning: articles) } } } - public func fetchArticlesAsync(articleIDs: Set) async throws -> Set
{ - try await withCheckedThrowingContinuation { continuation in - _fetchArticlesAsync(articleIDs: articleIDs) { result in - continuation.resume(with: result) + public func fetchArticlesAsync(articleIDs: Set) async -> Set
{ + await withCheckedContinuation { continuation in + _fetchArticlesAsync(articleIDs: articleIDs) { articles in + continuation.resume(returning: articles) } } } - public func fetchUnreadArticlesAsync(feedIDs: Set, limit: Int? = nil) async throws -> Set
{ - try await withCheckedThrowingContinuation { continuation in - _fetchUnreadArticlesAsync(feedIDs: feedIDs, limit: limit) { result in - continuation.resume(with: result) + public func fetchUnreadArticlesAsync(feedIDs: Set, limit: Int? = nil) async -> Set
{ + await withCheckedContinuation { continuation in + _fetchUnreadArticlesAsync(feedIDs: feedIDs, limit: limit) { articles in + continuation.resume(returning: articles) } } } - public func fetchTodayArticlesAsync(feedIDs: Set, limit: Int? = nil) async throws -> Set
{ - try await withCheckedThrowingContinuation { continuation in - _fetchTodayArticlesAsync(feedIDs: feedIDs, limit: limit) { result in - continuation.resume(with: result) + public func fetchTodayArticlesAsync(feedIDs: Set, limit: Int? = nil) async -> Set
{ + await withCheckedContinuation { continuation in + _fetchTodayArticlesAsync(feedIDs: feedIDs, limit: limit) { articles in + continuation.resume(returning: articles) } } } - public func fetchedStarredArticlesAsync(feedIDs: Set, limit: Int? = nil) async throws -> Set
{ - try await withCheckedThrowingContinuation { continuation in - _fetchedStarredArticlesAsync(feedIDs: feedIDs, limit: limit) { result in - continuation.resume(with: result) + public func fetchedStarredArticlesAsync(feedIDs: Set, limit: Int? = nil) async -> Set
{ + await withCheckedContinuation { continuation in + _fetchedStarredArticlesAsync(feedIDs: feedIDs, limit: limit) { articles in + continuation.resume(returning: articles) } } } - public func fetchArticlesMatchingAsync(searchString: String, feedIDs: Set) async throws -> Set
{ - try await withCheckedThrowingContinuation { continuation in - _fetchArticlesMatchingAsync(searchString: searchString, feedIDs: feedIDs) { result in - continuation.resume(with: result) + public func fetchArticlesMatchingAsync(searchString: String, feedIDs: Set) async -> Set
{ + await withCheckedContinuation { continuation in + _fetchArticlesMatchingAsync(searchString: searchString, feedIDs: feedIDs) { articles in + continuation.resume(returning: articles) } } } - public func fetchArticlesMatchingWithArticleIDsAsync(searchString: String, articleIDs: Set) async throws -> Set
{ - try await withCheckedThrowingContinuation { continuation in - _fetchArticlesMatchingWithArticleIDsAsync(searchString: searchString, articleIDs: articleIDs) { result in - continuation.resume(with: result) + public func fetchArticlesMatchingWithArticleIDsAsync(searchString: String, articleIDs: Set) async -> Set
{ + await withCheckedContinuation { continuation in + _fetchArticlesMatchingWithArticleIDsAsync(searchString: searchString, articleIDs: articleIDs) { articles in + continuation.resume(returning: articles) } } } @@ -294,8 +294,8 @@ public struct ArticleCounts: Sendable { /// Update articles and save new ones — for feed-based systems (local and iCloud). public func updateAsync(parsedItems: Set, feedID: String, deleteOlder: Bool) async throws -> ArticleChanges { try await withCheckedThrowingContinuation { continuation in - _update(parsedItems: parsedItems, feedID: feedID, deleteOlder: deleteOlder) { result in - continuation.resume(with: result) + _update(parsedItems: parsedItems, feedID: feedID, deleteOlder: deleteOlder) { articleChanges in + continuation.resume(returning: articleChanges) } } } @@ -303,8 +303,8 @@ public struct ArticleCounts: Sendable { /// Update articles and save new ones — for sync systems (Feedbin, Feedly, etc.). public func updateAsync(feedIDsAndItems: [String: Set], defaultRead: Bool) async throws -> ArticleChanges { try await withCheckedThrowingContinuation { continuation in - _update(feedIDsAndItems: feedIDsAndItems, defaultRead: defaultRead) { result in - continuation.resume(with: result) + _update(feedIDsAndItems: feedIDsAndItems, defaultRead: defaultRead) { articleChanges in + continuation.resume(returning: articleChanges) } } } @@ -327,16 +327,16 @@ public struct ArticleCounts: Sendable { /// Fetch the articleIDs of unread articles. public func fetchUnreadArticleIDsAsync() async throws -> Set { try await withCheckedThrowingContinuation { continuation in - _fetchUnreadArticleIDsAsync { result in - continuation.resume(with: result) + _fetchUnreadArticleIDsAsync { articleIDs in + continuation.resume(returning: articleIDs) } } } public func fetchStarredArticleIDsAsync() async throws -> Set { try await withCheckedThrowingContinuation { continuation in - _fetchStarredArticleIDsAsync { result in - continuation.resume(with: result) + _fetchStarredArticleIDsAsync { articleIDs in + continuation.resume(returning: articleIDs) } } } @@ -344,8 +344,8 @@ public struct ArticleCounts: Sendable { /// Fetch articleIDs for articles that we should have, but don’t. These articles are either starred or newer than the article cutoff date. public func fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDateAsync() async throws -> Set { try await withCheckedThrowingContinuation { continuation in - _fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate { result in - continuation.resume(with: result) + _fetchArticleIDsForStatusesWithoutArticlesNewerThanCutoffDate { articleIDs in + continuation.resume(returning: articleIDs) } } } @@ -354,16 +354,16 @@ public struct ArticleCounts: Sendable { public func markAsync(articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) async throws -> Set { try await withCheckedThrowingContinuation { continuation in - _mark(articles: articles, statusKey: statusKey, flag: flag) { result in - continuation.resume(with: result) + _mark(articles: articles, statusKey: statusKey, flag: flag) { statuses in + continuation.resume(returning: statuses) } } } public func markAndFetchNewAsync(articleIDs: Set, statusKey: ArticleStatus.Key, flag: Bool) async throws -> Set { try await withCheckedThrowingContinuation { continuation in - _markAndFetchNew(articleIDs: articleIDs, statusKey: statusKey, flag: flag) { result in - continuation.resume(with: result) + _markAndFetchNew(articleIDs: articleIDs, statusKey: statusKey, flag: flag) { articleIDs in + continuation.resume(returning: articleIDs) } } } @@ -444,20 +444,11 @@ private extension ArticlesDatabase { // MARK: - Articles Table (Private) typealias UnreadCountDictionaryCompletionBlock = @Sendable (UnreadCountDictionary) -> Void - -typealias UpdateArticlesResult = Result -typealias UpdateArticlesCompletionBlock = @Sendable (UpdateArticlesResult) -> Void - +typealias UpdateArticlesCompletionBlock = @Sendable (ArticleChanges) -> Void typealias SingleUnreadCountCompletionBlock = @Sendable (Int) -> Void - -typealias ArticleSetResult = Result, Error> -typealias ArticleSetResultBlock = @Sendable (ArticleSetResult) -> Void - -typealias ArticleIDsResult = Result, Error> -typealias ArticleIDsCompletionBlock = @Sendable (ArticleIDsResult) -> Void - -typealias ArticleStatusesResult = Result, Error> -typealias ArticleStatusesResultBlock = @Sendable (ArticleStatusesResult) -> Void +typealias ArticleSetResultBlock = @Sendable (Set
) -> Void +typealias ArticleIDsCompletionBlock = @Sendable (Set) -> Void +typealias ArticleStatusesResultBlock = @Sendable (Set) -> Void private extension ArticlesDatabase { diff --git a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift index 452c59d4b..514713148 100644 --- a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift +++ b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift @@ -132,7 +132,7 @@ final class ArticlesTable: DatabaseTable, Sendable { // MARK: - Fetching Search Articles - func fetchArticlesMatching(_ searchString: String) throws -> Set
{ + func fetchArticlesMatching(_ searchString: String) -> Set
{ nonisolated(unsafe) var articles: Set
= Set
() queue.runInDatabaseSync { database in @@ -142,14 +142,14 @@ final class ArticlesTable: DatabaseTable, Sendable { return articles } - func fetchArticlesMatching(_ searchString: String, _ feedIDs: Set) throws -> Set
{ - var articles = try fetchArticlesMatching(searchString) + func fetchArticlesMatching(_ searchString: String, _ feedIDs: Set) -> Set
{ + var articles = fetchArticlesMatching(searchString) articles = articles.filter { feedIDs.contains($0.feedID) } return articles } - func fetchArticlesMatchingWithArticleIDs(_ searchString: String, _ articleIDs: Set) throws -> Set
{ - var articles = try fetchArticlesMatching(searchString) + func fetchArticlesMatchingWithArticleIDs(_ searchString: String, _ articleIDs: Set) -> Set
{ + var articles = fetchArticlesMatching(searchString) articles = articles.filter { articleIDs.contains($0.articleID) } return articles } @@ -464,7 +464,7 @@ final class ArticlesTable: DatabaseTable, Sendable { self.queue.runInTransaction { database in let statuses = self.statusesTable.mark(articles.statuses(), statusKey, flag, database) DispatchQueue.main.async { - completion(.success(statuses ?? Set())) + completion(statuses ?? Set()) } } } @@ -473,7 +473,7 @@ final class ArticlesTable: DatabaseTable, Sendable { queue.runInTransaction { database in let newStatusIDs = self.statusesTable.markAndFetchNew(articleIDs, statusKey, flag, database) DispatchQueue.main.async { - completion(.success(newStatusIDs)) + completion(newStatusIDs) } } } @@ -647,7 +647,7 @@ nonisolated private extension ArticlesTable { queue.runInDatabase { database in let articles = fetchMethod(database) DispatchQueue.main.async { - completion(.success(articles)) + completion(articles) } } } @@ -908,7 +908,7 @@ nonisolated private extension ArticlesTable { func callUpdateArticlesCompletionBlock(_ newArticles: Set
?, _ updatedArticles: Set
?, _ deletedArticles: Set
?, _ completion: @escaping UpdateArticlesCompletionBlock) { let articleChanges = ArticleChanges(new: newArticles, updated: updatedArticles, deleted: deletedArticles) DispatchQueue.main.async { - completion(.success(articleChanges)) + completion(articleChanges) } } diff --git a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/StatusesTable.swift b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/StatusesTable.swift index cd924c311..389d3535d 100644 --- a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/StatusesTable.swift +++ b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/StatusesTable.swift @@ -111,14 +111,14 @@ final class StatusesTable: DatabaseTable, Sendable { guard let resultSet = database.executeQuery(sql, withArgumentsIn: nil) else { DispatchQueue.main.async { - completion(.success(Set())) + completion(Set()) } return } let articleIDs = resultSet.mapToSet { $0.swiftString(forColumnIndex: 0) } DispatchQueue.main.async { - completion(.success(articleIDs)) + completion(articleIDs) } } } @@ -134,7 +134,7 @@ final class StatusesTable: DatabaseTable, Sendable { } DispatchQueue.main.async { - completion(.success(articleIDs)) + completion(articleIDs) } } } diff --git a/Shared/Activity/ActivityManager.swift b/Shared/Activity/ActivityManager.swift index a24f989a3..ead6af594 100644 --- a/Shared/Activity/ActivityManager.swift +++ b/Shared/Activity/ActivityManager.swift @@ -300,12 +300,11 @@ import Images static func identifiers(for feed: Feed) -> [String] { var ids = [String]() ids.append(identifier(for: feed)) - if let articles = try? feed.fetchArticles() { - for article in articles { - ids.append(identifier(for: article)) - } + let articles = feed.fetchArticles() + for article in articles { + ids.append(identifier(for: article)) } - + return ids } } diff --git a/Shared/SmartFeeds/SmartFeed.swift b/Shared/SmartFeeds/SmartFeed.swift index bd30d966f..1305d402e 100644 --- a/Shared/SmartFeeds/SmartFeed.swift +++ b/Shared/SmartFeeds/SmartFeed.swift @@ -85,20 +85,20 @@ import Images extension SmartFeed: ArticleFetcher { - func fetchArticles() throws -> Set
{ - try delegate.fetchArticles() + func fetchArticles() -> Set
{ + delegate.fetchArticles() } - func fetchArticlesAsync() async throws -> Set
{ - try await delegate.fetchArticlesAsync() + func fetchArticlesAsync() async -> Set
{ + await delegate.fetchArticlesAsync() } - func fetchUnreadArticles() throws -> Set
{ - try delegate.fetchUnreadArticles() + func fetchUnreadArticles() -> Set
{ + delegate.fetchUnreadArticles() } - func fetchUnreadArticlesAsync() async throws -> Set
{ - try await delegate.fetchUnreadArticlesAsync() + func fetchUnreadArticlesAsync() async -> Set
{ + await delegate.fetchUnreadArticlesAsync() } } diff --git a/Shared/SmartFeeds/SmartFeedDelegate.swift b/Shared/SmartFeeds/SmartFeedDelegate.swift index aa216dfe2..c7c3775f6 100644 --- a/Shared/SmartFeeds/SmartFeedDelegate.swift +++ b/Shared/SmartFeeds/SmartFeedDelegate.swift @@ -19,20 +19,20 @@ import RSCore @MainActor extension SmartFeedDelegate { - func fetchArticles() throws -> Set
{ - return try AccountManager.shared.fetchArticles(fetchType) + func fetchArticles() -> Set
{ + AccountManager.shared.fetchArticles(fetchType) } - func fetchArticlesAsync() async throws -> Set
{ - try await AccountManager.shared.fetchArticlesAsync(fetchType) + func fetchArticlesAsync() async -> Set
{ + await AccountManager.shared.fetchArticlesAsync(fetchType) } - func fetchUnreadArticles() throws -> Set
{ - try fetchArticles().unreadArticles() + func fetchUnreadArticles() -> Set
{ + fetchArticles().unreadArticles() } - func fetchUnreadArticlesAsync() async throws -> Set
{ - let articles = try await fetchArticlesAsync() + func fetchUnreadArticlesAsync() async -> Set
{ + let articles = await fetchArticlesAsync() return articles.unreadArticles() } } diff --git a/Shared/SmartFeeds/UnreadFeed.swift b/Shared/SmartFeeds/UnreadFeed.swift index 87a155a1e..15e29c23f 100644 --- a/Shared/SmartFeeds/UnreadFeed.swift +++ b/Shared/SmartFeeds/UnreadFeed.swift @@ -67,19 +67,19 @@ import Images @MainActor extension UnreadFeed: ArticleFetcher { - func fetchArticles() throws -> Set
{ - return try fetchUnreadArticles() + func fetchArticles() -> Set
{ + fetchUnreadArticles() } - func fetchArticlesAsync() async throws -> Set
{ - try await fetchUnreadArticlesAsync() + func fetchArticlesAsync() async -> Set
{ + await fetchUnreadArticlesAsync() } - func fetchUnreadArticles() throws -> Set
{ - try AccountManager.shared.fetchArticles(fetchType) + func fetchUnreadArticles() -> Set
{ + AccountManager.shared.fetchArticles(fetchType) } - func fetchUnreadArticlesAsync() async throws -> Set
{ - try await AccountManager.shared.fetchArticlesAsync(fetchType) + func fetchUnreadArticlesAsync() async -> Set
{ + await AccountManager.shared.fetchArticlesAsync(fetchType) } } diff --git a/Shared/Timeline/FetchRequestOperation.swift b/Shared/Timeline/FetchRequestOperation.swift index 86f73cd94..c88067fe7 100644 --- a/Shared/Timeline/FetchRequestOperation.swift +++ b/Shared/Timeline/FetchRequestOperation.swift @@ -94,17 +94,13 @@ typealias FetchRequestOperationResultBlock = (Set
, FetchRequestOperatio for fetcher in fetchers { let articles: Set
- do { - if (fetcher as? SidebarItem)?.readFiltered(readFilterEnabledTable: readFilterEnabledTable) ?? true { - articles = try await fetcher.fetchUnreadArticlesAsync() - } else { - articles = try await fetcher.fetchArticlesAsync() - } - } catch { - Self.logger.error("FetchRequestOperation \(self.id, privacy: .public): fetcher threw — \(String(describing: error), privacy: .public)") - Self.postFetchError(error) - articles = [] + + if (fetcher as? SidebarItem)?.readFiltered(readFilterEnabledTable: readFilterEnabledTable) ?? true { + articles = await fetcher.fetchUnreadArticlesAsync() + } else { + articles = await fetcher.fetchArticlesAsync() } + process(articles) } @@ -193,16 +189,10 @@ typealias FetchRequestOperationResultBlock = (Set
, FetchRequestOperatio for fetcher in fetchers { let articles: Set
- do { - if fetcherHidesReadArticles(fetcher) { - articles = try await fetcher.fetchUnreadArticlesAsync() - } else { - articles = try await fetcher.fetchArticlesAsync() - } - } catch { - Self.logger.error("FetchRequestOperation \(self.id, privacy: .public): fetcher threw — \(String(describing: error), privacy: .public)") - Self.postFetchError(error) - articles = [] + if fetcherHidesReadArticles(fetcher) { + articles = await fetcher.fetchUnreadArticlesAsync() + } else { + articles = await fetcher.fetchArticlesAsync() } process(articles) } diff --git a/Shared/Widget/WidgetDataEncoder.swift b/Shared/Widget/WidgetDataEncoder.swift index fd5e0cf88..b85efa9b4 100644 --- a/Shared/Widget/WidgetDataEncoder.swift +++ b/Shared/Widget/WidgetDataEncoder.swift @@ -57,15 +57,7 @@ import Account removeStaleFaviconsFromSharedContainer() - let latestData: WidgetData - do { - latestData = try fetchWidgetData() - Self.logger.debug("WidgetDataEncoder: fetched latest widget data") - } catch { - Self.logger.error("WidgetDataEncoder: error fetching widget data: \(error.localizedDescription)") - return - } - + let latestData = fetchWidgetData() let encodedData: Data do { encodedData = try JSONEncoder().encode(latestData) @@ -118,15 +110,15 @@ import Account @MainActor private extension WidgetDataEncoder { - func fetchWidgetData() throws -> WidgetData { - let fetchedUnreadArticles = try AccountManager.shared.fetchArticles(.unread(fetchLimit)) + func fetchWidgetData() -> WidgetData { + let fetchedUnreadArticles = AccountManager.shared.fetchArticles(.unread(fetchLimit)) let unreadArticles = sortedLatestArticles(fetchedUnreadArticles) - let fetchedStarredArticles = try AccountManager.shared.fetchArticles(.starred(fetchLimit)) + let fetchedStarredArticles = AccountManager.shared.fetchArticles(.starred(fetchLimit)) let starredArticles = sortedLatestArticles(fetchedStarredArticles) - let fetchedTodayArticles = try AccountManager.shared.fetchArticles(.today(fetchLimit)) - let fetchedTodayTotal = try AccountManager.shared.fetchArticles(.today()) + let fetchedTodayArticles = AccountManager.shared.fetchArticles(.today(fetchLimit)) + let fetchedTodayTotal = AccountManager.shared.fetchArticles(.today()) let fetchedTodayTotalCount = fetchedTodayTotal.count let fetchedTodayUnreadCount = fetchedTodayTotal.filter({ $0.status.read == false }).count let todayArticles = sortedLatestArticles(fetchedTodayArticles) @@ -134,7 +126,7 @@ import Account let latestData = WidgetData(totalUnreadCount: SmartFeedsController.shared.unreadFeed.unreadCount, totalTodayCount: fetchedTodayTotalCount, totalTodayUnreadCount: fetchedTodayUnreadCount, - totalStarredCount: (try? AccountManager.shared.fetchCountForStarredArticles()) ?? 0, + totalStarredCount: AccountManager.shared.fetchCountForStarredArticles(), unreadArticles: unreadArticles, starredArticles: starredArticles, todayArticles: todayArticles, diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index 0a32ee06b..a29334c07 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -458,12 +458,7 @@ private extension AppDelegate { return } - guard let singleArticleSet = try? account.fetchArticles(.articleIDs([articleID])) else { - assertionFailure("Expected article with \(articleID)") - Self.logger.error("No article with articleID found \(articleID) from status notification") - return - } - + let singleArticleSet = account.fetchArticles(.articleIDs([articleID])) assert(singleArticleSet.count == 1) account.markArticles(singleArticleSet, statusKey: statusKey, flag: true) { _ in } diff --git a/iOS/MainFeed/MainFeedCollectionViewController.swift b/iOS/MainFeed/MainFeedCollectionViewController.swift index e7dc4cd07..0fbbbca1a 100644 --- a/iOS/MainFeed/MainFeedCollectionViewController.swift +++ b/iOS/MainFeed/MainFeedCollectionViewController.swift @@ -1132,8 +1132,11 @@ extension MainFeedCollectionViewController { func markAllAsReadAlertAction(indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? { guard let feed = dataSource.itemIdentifier(for: indexPath)?.node.representedObject as? Feed, - feed.unreadCount > 0, - let articles = try? feed.fetchArticles(), let contentView = self.collectionView.cellForItem(at: indexPath)?.contentView else { + feed.unreadCount > 0 else { + return nil + } + let articles = feed.fetchArticles() + guard let contentView = self.collectionView.cellForItem(at: indexPath)?.contentView else { return nil } @@ -1229,9 +1232,8 @@ extension MainFeedCollectionViewController { let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, sidebarItem.nameForDisplay) as String let action = UIAction(title: title, image: Assets.Images.markAllAsRead) { [weak self] _ in MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in - if let articles = try? sidebarItem.fetchUnreadArticles() { - self?.coordinator.markAllAsRead(Array(articles)) - } + let articles = sidebarItem.fetchUnreadArticles() + self?.coordinator.markAllAsRead(Array(articles)) } } @@ -1249,9 +1251,8 @@ extension MainFeedCollectionViewController { MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in // If you don't have this delay the screen flashes when it executes this code DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - if let articles = try? account.fetchArticles(.unread()) { - self?.coordinator.markAllAsRead(Array(articles)) - } + let articles = account.fetchArticles(.unread()) + self?.coordinator.markAllAsRead(Array(articles)) } } } diff --git a/iOS/MainTimeline/MainTimelineModernViewController.swift b/iOS/MainTimeline/MainTimelineModernViewController.swift index b7805c5e1..2025945f9 100644 --- a/iOS/MainTimeline/MainTimelineModernViewController.swift +++ b/iOS/MainTimeline/MainTimelineModernViewController.swift @@ -1299,11 +1299,11 @@ extension MainTimelineModernViewController { } func markAllInFeedAsReadAction(_ article: Article, indexPath: IndexPath) -> UIAction? { - guard let feed = article.feed else { return nil } - guard let fetchedArticles = try? feed.fetchArticles() else { + guard let feed = article.feed else { return nil } + let fetchedArticles = feed.fetchArticles() let articles = Array(fetchedArticles) guard articles.canMarkAllAsRead(), let collectionView, let contentView = collectionView.cellForItem(at: indexPath)?.contentView else { return nil @@ -1321,11 +1321,11 @@ extension MainTimelineModernViewController { } func markAllInFeedAsReadAlertAction(_ article: Article, indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? { - guard let feed = article.feed else { return nil } - guard let fetchedArticles = try? feed.fetchArticles() else { + guard let feed = article.feed else { return nil } + let fetchedArticles = feed.fetchArticles() let articles = Array(fetchedArticles) guard articles.canMarkAllAsRead(), let collectionView, let contentView = collectionView.cellForItem(at: indexPath)?.contentView else { return nil