Code cleanup

This commit is contained in:
Maurice Parker
2022-11-12 12:33:25 -06:00
parent 0ea57c21c2
commit c24ea4d1b5
2 changed files with 34 additions and 58 deletions

View File

@@ -1050,41 +1050,31 @@ extension AppDelegate: NSWindowRestoration {
private extension AppDelegate {
func handleMarkAsRead(userInfo: [AnyHashable: Any]) {
markArticle(userInfo: userInfo, statusKey: .read)
}
func handleMarkAsStarred(userInfo: [AnyHashable: Any]) {
markArticle(userInfo: userInfo, statusKey: .starred)
}
func markArticle(userInfo: [AnyHashable: Any], statusKey: ArticleStatus.Key) {
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
}
let account = AccountManager.shared.existingAccount(with: accountID)
guard account != nil else {
guard let account = AccountManager.shared.existingAccount(with: accountID) else {
logger.debug("No account found from notification.")
return
}
let article = try? account!.fetchArticles(.articleIDs([articleID]))
guard article != nil else {
guard let articles = try? account.fetchArticles(.articleIDs([articleID])), !articles.isEmpty else {
logger.debug("No article found from search using: \(articleID, privacy: .public)")
return
}
account!.markArticles(article!, statusKey: .read, flag: true) { _ in }
account.mark(articles: articles, statusKey: statusKey, flag: true) { _ in }
}
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
}
let account = AccountManager.shared.existingAccount(with: accountID)
guard account != nil else {
logger.debug("No account found from notification.")
return
}
let article = try? account!.fetchArticles(.articleIDs([articleID]))
guard article != nil else {
logger.debug("No article found from search using: \(articleID, privacy: .public)")
return
}
account!.markArticles(article!, statusKey: .starred, flag: true) { _ in }
}
}

View File

@@ -10,6 +10,7 @@ import UIKit
import RSCore
import RSWeb
import Account
import Articles
import BackgroundTasks
import Secrets
import WidgetKit
@@ -432,55 +433,40 @@ 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
}
resumeDatabaseProcessingIfNecessary()
let account = AccountManager.shared.existingAccount(with: accountID)
guard account != nil else {
logger.debug("No account found from notification.")
return
}
let article = try? account!.fetchArticles(.articleIDs([articleID]))
guard article != nil else {
logger.debug("No account found from search using \(articleID, privacy: .public)")
return
}
account!.markArticles(article!, statusKey: .read, flag: true) { _ in }
self.prepareAccountsForBackground()
account!.syncArticleStatus(completion: { [weak self] _ in
if !AccountManager.shared.isSuspended {
self?.prepareAccountsForBackground()
self?.suspendApplication()
}
})
markArticle(userInfo: userInfo, statusKey: .read)
}
func handleMarkAsStarred(userInfo: [AnyHashable: Any]) {
markArticle(userInfo: userInfo, statusKey: .starred)
}
func markArticle(userInfo: [AnyHashable: Any], statusKey: ArticleStatus.Key) {
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
}
resumeDatabaseProcessingIfNecessary()
let account = AccountManager.shared.existingAccount(with: accountID)
guard account != nil else {
guard let account = AccountManager.shared.existingAccount(with: accountID) else {
logger.debug("No account found from notification.")
return
}
let article = try? account!.fetchArticles(.articleIDs([articleID]))
guard article != nil else {
guard let articles = try? account.fetchArticles(.articleIDs([articleID])), !articles.isEmpty else {
logger.debug("No article found from search using \(articleID, privacy: .public)")
return
}
account!.markArticles(article!, statusKey: .starred, flag: true) { _ in }
account!.syncArticleStatus(completion: { [weak self] _ in
if !AccountManager.shared.isSuspended {
self?.prepareAccountsForBackground()
self?.suspendApplication()
}
})
account.mark(articles: articles, statusKey: statusKey, flag: true) { [weak self] _ in
account.syncArticleStatus(completion: { [weak self] _ in
if !AccountManager.shared.isSuspended {
self?.prepareAccountsForBackground()
self?.suspendApplication()
}
})
}
}
}