diff --git a/Evergreen/Data/DefaultFeedsImporter.swift b/Evergreen/Data/DefaultFeedsImporter.swift index b26571178..31c1570ce 100644 --- a/Evergreen/Data/DefaultFeedsImporter.swift +++ b/Evergreen/Data/DefaultFeedsImporter.swift @@ -10,44 +10,58 @@ import Foundation import Data import Account -private func shouldImportDefaultFeeds(_ isFirstRun: Bool) -> Bool { - - if !isFirstRun { - return false - } +private typealias DiskFeedDictionary = [String: String] - for oneAccount in AccountManager.shared.accounts { - if oneAccount.hasAtLeastOneFeed { +struct DefaultFeedsImporter { + + static func importIfNeeded(_ firstRun: Bool, account: Account) { + + if shouldImportDefaultFeeds(firstRun) { + FeedsImporter.import(defaultFeeds(), account: account) + } + } + + private static func defaultFeeds() -> [DiskFeedDictionary] { + + let f = Bundle.main.path(forResource: "DefaultFeeds", ofType: "plist")! + return NSArray(contentsOfFile: f)! as! [DiskFeedDictionary] + } + + private static func shouldImportDefaultFeeds(_ isFirstRun: Bool) -> Bool { + + if !isFirstRun { return false } - } - return true -} - -private func defaultFeedsArray() -> NSArray { - - let f = Bundle.main.path(forResource: "DefaultFeeds", ofType: "plist")! - return NSArray(contentsOfFile: f)! -} - -private func importFeedsWithArray(_ defaultFeeds: NSArray, _ account: Account) { - - for d in defaultFeeds { - - guard let oneFeedDictionary = d as? NSDictionary else { - continue + + for oneAccount in AccountManager.shared.accounts { + if oneAccount.hasAtLeastOneFeed() { + return false + } } - - let oneFeed = LocalFeed(account: account, diskDictionary: oneFeedDictionary)! - let _ = account.addItem(oneFeed) + return true } } -func importDefaultFeedsIfNeeded(_ isFirstRun: Bool, account: Account) { +struct FeedsImporter { - if !shouldImportDefaultFeeds(isFirstRun) { - return + func import(_ feedDictionaries: [DiskFeedDictionary], account: Account) { + + let feeds = feeds(with: feedDictionaries) + feeds.forEach { let _ = account.addItem($0) } + } + + private func feeds(with feedDictionaries: [DiskFeedDictionary]) -> Set { + + let feeds = Set(feedDictionaries.map { Feed(account: account, diskFeedDictionary: $0) }) + return feeds } - - importFeedsWithArray(defaultFeedsArray(), account) } + +private extension Feed { + + init?(account: Account, diskFeedDictionary: DiskFeedDictionary) { + + + } +} + diff --git a/Evergreen/MainWindow/Timeline/TimelineViewController.swift b/Evergreen/MainWindow/Timeline/TimelineViewController.swift index 409d36b3e..93ab63ab7 100644 --- a/Evergreen/MainWindow/Timeline/TimelineViewController.swift +++ b/Evergreen/MainWindow/Timeline/TimelineViewController.swift @@ -86,7 +86,6 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView // MARK: KVO - override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { if let keyPath = keyPath { diff --git a/Frameworks/Account/Extensions/Feed+Account.swift b/Frameworks/Account/Extensions/Feed+Account.swift index 3f032fecc..2dd27b523 100644 --- a/Frameworks/Account/Extensions/Feed+Account.swift +++ b/Frameworks/Account/Extensions/Feed+Account.swift @@ -9,6 +9,11 @@ import Foundation import Data +struct FeedDictionaryKey { + + +} + public extension Feed { var account: Account? { @@ -16,4 +21,13 @@ public extension Feed { return accountWithID(accountID) } } + + struct DictionaryKey { + static let + } + + init?(accountID: String, feedDictionary: FeedDictionary) { + + + } } diff --git a/Frameworks/RSWeb/RSWeb/HTTPConditionalGetInfo.swift b/Frameworks/RSWeb/RSWeb/HTTPConditionalGetInfo.swift index 40f8f15a5..b086f8d3b 100755 --- a/Frameworks/RSWeb/RSWeb/HTTPConditionalGetInfo.swift +++ b/Frameworks/RSWeb/RSWeb/HTTPConditionalGetInfo.swift @@ -8,7 +8,7 @@ import Foundation -public struct HTTPConditionalGetInfo { +public struct HTTPConditionalGetInfo: Codable { public let lastModified: String? public let etag: String? @@ -18,22 +18,6 @@ public struct HTTPConditionalGetInfo { } } - public var plist: [String: String]? { - get { - if isEmpty { - return nil - } - var d = [String: String]() - if let lastModified = lastModified { - d[HTTPResponseHeader.lastModified] = lastModified - } - if let etag = etag { - d[HTTPResponseHeader.etag] = etag - } - return d - } - } - public init(lastModified: String?, etag: String?) { self.lastModified = lastModified @@ -48,11 +32,6 @@ public struct HTTPConditionalGetInfo { self.init(lastModified: lastModified, etag: etag) } - public init(plist: [String: String]) { - - self.init(lastModified: plist[HTTPResponseHeader.lastModified], etag: plist[HTTPResponseHeader.etag]) - } - public func addRequestHeadersToURLRequest(_ urlRequest: NSMutableURLRequest) { if let lastModified = lastModified {