Fix build errors.

This commit is contained in:
Brent Simmons
2024-03-19 10:15:30 -07:00
parent 5c6e5807d9
commit b2d3128b2d
11 changed files with 256 additions and 184 deletions

View File

@@ -421,58 +421,70 @@ private extension AppDelegate {
private extension AppDelegate {
func handleMarkAsRead(userInfo: [AnyHashable: Any]) {
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any],
let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,
let articleID = articlePathUserInfo[ArticlePathKey.articleID] as? String else {
return
@MainActor func handleMarkAsRead(userInfo: [AnyHashable: Any]) {
guard let articlePathInfo = ArticlePathInfo(userInfo: userInfo) else {
return
}
resumeDatabaseProcessingIfNecessary()
let account = AccountManager.shared.existingAccount(with: accountID)
guard account != nil else {
guard let account = AccountManager.shared.existingAccount(with: articlePathInfo.accountID) else {
os_log(.debug, "No account found from notification.")
return
}
let article = try? account!.fetchArticles(.articleIDs([articleID]))
guard article != nil else {
os_log(.debug, "No article found from search using %@", articleID)
return
}
account!.markArticles(article!, statusKey: .read, flag: true) { _ in }
self.prepareAccountsForBackground()
account!.syncArticleStatus(completion: { [weak self] _ in
if !AccountManager.shared.isSuspended {
try? WidgetDataEncoder.shared.encodeWidgetData()
self?.prepareAccountsForBackground()
self?.suspendApplication()
let articleID = articlePathInfo.articleID
Task { @MainActor in
guard let articles = try? await account.articles(for: .articleIDs([articleID])) else {
os_log(.debug, "No article found from search using %@", articleID)
return
}
})
account.markArticles(articles, statusKey: .read, flag: true) { _ in }
self.prepareAccountsForBackground()
account.syncArticleStatus(completion: { [weak self] _ in
if !AccountManager.shared.isSuspended {
try? WidgetDataEncoder.shared.encodeWidgetData()
self?.prepareAccountsForBackground()
self?.suspendApplication()
}
})
}
}
func handleMarkAsStarred(userInfo: [AnyHashable: Any]) {
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any],
let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,
let articleID = articlePathUserInfo[ArticlePathKey.articleID] as? String else {
return
@MainActor func handleMarkAsStarred(userInfo: [AnyHashable: Any]) {
guard let articlePathInfo = ArticlePathInfo(userInfo: userInfo) else {
return
}
resumeDatabaseProcessingIfNecessary()
let account = AccountManager.shared.existingAccount(with: accountID)
guard account != nil else {
guard let account = AccountManager.shared.existingAccount(with: articlePathInfo.accountID) else {
os_log(.debug, "No account found from notification.")
return
}
let article = try? account!.fetchArticles(.articleIDs([articleID]))
guard article != nil else {
os_log(.debug, "No article found from search using %@", articleID)
return
}
account!.markArticles(article!, statusKey: .starred, flag: true) { _ in }
account!.syncArticleStatus(completion: { [weak self] _ in
if !AccountManager.shared.isSuspended {
try? WidgetDataEncoder.shared.encodeWidgetData()
self?.prepareAccountsForBackground()
self?.suspendApplication()
let articleID = articlePathInfo.articleID
Task { @MainActor in
guard let articles = try? await account.articles(for: .articleIDs([articleID])) else {
os_log(.debug, "No article found from search using %@", articleID)
return
}
})
account.markArticles(articles, statusKey: .starred, flag: true) { _ in }
account.syncArticleStatus(completion: { [weak self] _ in
if !AccountManager.shared.isSuspended {
try? WidgetDataEncoder.shared.encodeWidgetData()
self?.prepareAccountsForBackground()
self?.suspendApplication()
}
})
}
}
}

View File

@@ -986,6 +986,7 @@ private extension SidebarViewController {
}
func copyHomePageAlertAction(indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? {
guard let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed,
let homePageURL = feed.homePageURL,
let url = URL(string: homePageURL) else {
@@ -1001,9 +1002,12 @@ private extension SidebarViewController {
}
func markAllAsReadAlertAction(indexPath: IndexPath, completion: @escaping (Bool) -> Void) -> UIAlertAction? {
guard let feed = coordinator.nodeFor(indexPath)?.representedObject as? Feed,
feed.unreadCount > 0,
let articles = try? feed.fetchArticles(), let contentView = self.tableView.cellForRow(at: indexPath)?.contentView else {
feed.unreadCount > 0 else {
return nil
}
guard let contentView = self.tableView.cellForRow(at: indexPath)?.contentView else {
return nil
}
@@ -1016,8 +1020,13 @@ private extension SidebarViewController {
let action = UIAlertAction(title: title, style: .default) { [weak self] action in
MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView, cancelCompletion: cancel) { [weak self] in
self?.coordinator.markAllAsRead(Array(articles))
completion(true)
Task { @MainActor in
if let articles = try? await feed.fetchUnreadArticles() {
self?.coordinator.markAllAsRead(Array(articles))
}
completion(true)
}
}
}
return action
@@ -1092,8 +1101,11 @@ private extension SidebarViewController {
let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String
let action = UIAction(title: title, image: AppAssets.markAllAsReadImage) { [weak self] action in
MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in
if let articles = try? feed.fetchUnreadArticles() {
self?.coordinator.markAllAsRead(Array(articles))
Task { @MainActor in
if let articles = try? await feed.fetchUnreadArticles() {
self?.coordinator.markAllAsRead(Array(articles))
}
}
}
}
@@ -1112,8 +1124,11 @@ private extension SidebarViewController {
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))
Task { @MainActor in
if let articles = try? await account.articles(for: .unread()) {
self?.coordinator.markAllAsRead(Array(articles))
}
}
}
}

View File

@@ -51,8 +51,8 @@ struct SidebarItemNode: Hashable {
}
}
class SceneCoordinator: NSObject, UndoableCommandRunner {
@MainActor final class SceneCoordinator: NSObject, UndoableCommandRunner {
var undoableCommands = [UndoableCommand]()
var undoManager: UndoManager? {
return rootSplitViewController.undoManager

View File

@@ -867,36 +867,37 @@ private extension TimelineViewController {
}
func markAllInFeedAsReadAction(_ article: Article, indexPath: IndexPath) -> UIAction? {
guard let feed = article.feed else { return nil }
guard let fetchedArticles = try? feed.fetchArticles() else {
return nil
}
let articles = Array(fetchedArticles)
guard articles.canMarkAllAsRead(), let contentView = self.tableView.cellForRow(at: indexPath)?.contentView else {
guard let feed = article.feed, feed.unreadCount > 0 else {
return nil
}
guard let contentView = self.tableView.cellForRow(at: indexPath)?.contentView else {
return nil
}
let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command")
let title = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String
let action = UIAction(title: title, image: AppAssets.markAllAsReadImage) { [weak self] action in
MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView) { [weak self] in
self?.coordinator.markAllAsRead(articles)
Task { @MainActor in
if let articles = try? await feed.fetchArticles() {
self?.coordinator.markAllAsRead(Array(articles))
}
}
}
}
return action
}
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, feed.unreadCount > 0 else {
return nil
}
let articles = Array(fetchedArticles)
guard articles.canMarkAllAsRead(), let contentView = self.tableView.cellForRow(at: indexPath)?.contentView else {
guard let contentView = self.tableView.cellForRow(at: indexPath)?.contentView else {
return nil
}
@@ -908,8 +909,15 @@ private extension TimelineViewController {
let action = UIAlertAction(title: title, style: .default) { [weak self] action in
MarkAsReadAlertController.confirm(self, coordinator: self?.coordinator, confirmTitle: title, sourceType: contentView, cancelCompletion: cancel) { [weak self] in
self?.coordinator.markAllAsRead(articles)
completion(true)
Task { @MainActor in
if let articles = try? await feed.fetchArticles() {
self?.coordinator.markAllAsRead(Array(articles))
completion(true)
} else {
completion(false)
}
}
}
}
return action