Refactor SmartFeedController to find SmartFeeds by FeedIdentifier instead of the string identifier.

This commit is contained in:
Maurice Parker 2019-11-23 12:30:18 -06:00
parent 01f86d8c1b
commit 6d18cfec7c
2 changed files with 20 additions and 15 deletions

View File

@ -24,14 +24,19 @@ final class SmartFeedsController: DisplayNameProvider {
self.smartFeeds = [todayFeed, unreadFeed, starredFeed] self.smartFeeds = [todayFeed, unreadFeed, starredFeed]
} }
func find(by identifier: String) -> PseudoFeed? { func find(by identifier: FeedIdentifier) -> PseudoFeed? {
switch identifier { switch identifier {
case String(describing: TodayFeedDelegate.self): case .smartFeed(let stringIdentifer):
return todayFeed switch stringIdentifer {
case String(describing: UnreadFeed.self): case String(describing: TodayFeedDelegate.self):
return unreadFeed return todayFeed
case String(describing: StarredFeedDelegate.self): case String(describing: UnreadFeed.self):
return starredFeed return unreadFeed
case String(describing: StarredFeedDelegate.self):
return starredFeed
default:
return nil
}
default: default:
return nil return nil
} }

View File

@ -1684,14 +1684,14 @@ private extension SceneCoordinator {
func handleSelectFeed(_ userInfo: [AnyHashable : Any]?) { func handleSelectFeed(_ userInfo: [AnyHashable : Any]?) {
guard let userInfo = userInfo, guard let userInfo = userInfo,
let feedIdentifierUserInfo = userInfo[UserInfoKey.feedIdentifier] as? [AnyHashable : Any], let feedIdentifierUserInfo = userInfo[UserInfoKey.feedIdentifier] as? [AnyHashable : Any],
let articleFetcherType = FeedIdentifier(userInfo: feedIdentifierUserInfo) else { let feedIdentifier = FeedIdentifier(userInfo: feedIdentifierUserInfo) else {
return return
} }
switch articleFetcherType { switch feedIdentifier {
case .smartFeed(let identifier): case .smartFeed:
guard let smartFeed = SmartFeedsController.shared.find(by: identifier) else { return } guard let smartFeed = SmartFeedsController.shared.find(by: feedIdentifier) else { return }
if let indexPath = indexPathFor(smartFeed) { if let indexPath = indexPathFor(smartFeed) {
selectFeed(indexPath, animated: false) selectFeed(indexPath, animated: false)
} }
@ -1744,14 +1744,14 @@ private extension SceneCoordinator {
func restoreFeed(_ userInfo: [AnyHashable : Any], accountID: String, webFeedID: String, articleID: String) -> Bool { func restoreFeed(_ userInfo: [AnyHashable : Any], accountID: String, webFeedID: String, articleID: String) -> Bool {
guard let feedIdentifierUserInfo = userInfo[UserInfoKey.feedIdentifier] as? [AnyHashable : Any], guard let feedIdentifierUserInfo = userInfo[UserInfoKey.feedIdentifier] as? [AnyHashable : Any],
let articleFetcherType = FeedIdentifier(userInfo: feedIdentifierUserInfo) else { let feedIdentifier = FeedIdentifier(userInfo: feedIdentifierUserInfo) else {
return false return false
} }
switch articleFetcherType { switch feedIdentifier {
case .smartFeed(let identifier): case .smartFeed:
guard let smartFeed = SmartFeedsController.shared.find(by: identifier) else { return false } guard let smartFeed = SmartFeedsController.shared.find(by: feedIdentifier) else { return false }
if smartFeed.fetchArticles().contains(accountID: accountID, articleID: articleID) { if smartFeed.fetchArticles().contains(accountID: accountID, articleID: articleID) {
if let indexPath = indexPathFor(smartFeed) { if let indexPath = indexPathFor(smartFeed) {
selectFeed(indexPath, animated: false) { selectFeed(indexPath, animated: false) {