Restore Smart Feed or Folder path if possible when restoring an Article. Issue #1241

This commit is contained in:
Maurice Parker 2019-11-15 18:26:52 -06:00
parent d3e5985258
commit 16da609fa9
2 changed files with 63 additions and 5 deletions

View File

@ -78,6 +78,11 @@ public extension Set where Element == Article {
let articles = self.filter { !$0.status.read }
return Set(articles)
}
func contains(accountID: String, articleID: String) -> Bool {
return contains(where: { $0.accountID == accountID && $0.articleID == articleID})
}
}
public extension Array where Element == Article {
@ -85,4 +90,5 @@ public extension Array where Element == Article {
func articleIDs() -> [String] {
return map { $0.articleID }
}
}

View File

@ -1656,8 +1656,9 @@ private extension SceneCoordinator {
}
func handleReadArticle(_ userInfo: [AnyHashable : Any]?) {
guard let userInfo = userInfo,
let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any],
guard let userInfo = userInfo else { return }
guard let articlePathUserInfo = userInfo[UserInfoKey.articlePath] as? [AnyHashable : Any],
let accountID = articlePathUserInfo[ArticlePathKey.accountID] as? String,
let accountName = articlePathUserInfo[ArticlePathKey.accountName] as? String,
let webFeedID = articlePathUserInfo[ArticlePathKey.webFeedID] as? String,
@ -1665,17 +1666,62 @@ private extension SceneCoordinator {
return
}
if restoreFeed(userInfo, accountID: accountID, articleID: articleID) {
return
}
guard let accountNode = findAccountNode(accountID: accountID, accountName: accountName), let feedNode = findWebFeedNode(webFeedID: webFeedID, beginningAt: accountNode) else {
return
}
discloseFeed(feedNode.representedObject as! WebFeed, animated: false) {
if let article = self.articles.first(where: { $0.articleID == articleID }) {
self.selectArticle(article)
}
self.selectArticleInCurrentFeed(articleID)
}
}
func restoreFeed(_ userInfo: [AnyHashable : Any], accountID: String, articleID: String) -> Bool {
guard let feedIdentifierUserInfo = userInfo[UserInfoKey.feedIdentifier] as? [AnyHashable : Any],
let articleFetcherType = FeedIdentifier(userInfo: feedIdentifierUserInfo) else {
return false
}
switch articleFetcherType {
case .smartFeed(let identifier):
guard let smartFeed = SmartFeedsController.shared.find(by: identifier) else { return false }
if smartFeed.fetchArticles().contains(accountID: accountID, articleID: articleID) {
if let indexPath = indexPathFor(smartFeed) {
selectFeed(indexPath, animated: false)
selectArticleInCurrentFeed(articleID)
return true
}
}
case .script:
return false
case .folder(let accountID, let folderName):
guard let accountNode = findAccountNode(accountID: accountID),
let folderNode = findFolderNode(folderName: folderName, beginningAt: accountNode),
let folderFeed = folderNode.representedObject as? Feed else {
return false
}
if folderFeed.fetchArticles().contains(accountID: accountID, articleID: articleID) {
if let indexPath = indexPathFor(folderNode) {
selectFeed(indexPath, animated: false)
selectArticleInCurrentFeed(articleID)
return true
}
}
case .webFeed:
return false
}
return false
}
func findAccountNode(accountID: String, accountName: String? = nil) -> Node? {
if let node = treeController.rootNode.descendantNode(where: { ($0.representedObject as? Account)?.accountID == accountID }) {
return node
@ -1702,4 +1748,10 @@ private extension SceneCoordinator {
return nil
}
func selectArticleInCurrentFeed(_ articleID: String) {
if let article = self.articles.first(where: { $0.articleID == articleID }) {
self.selectArticle(article)
}
}
}