Start work on feed importing.

This commit is contained in:
Brent Simmons 2017-09-24 22:35:57 -07:00
parent 4d677b2055
commit 21080a97fc
4 changed files with 60 additions and 54 deletions

View File

@ -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<Feed> {
let feeds = Set(feedDictionaries.map { Feed(account: account, diskFeedDictionary: $0) })
return feeds
}
importFeedsWithArray(defaultFeedsArray(), account)
}
private extension Feed {
init?(account: Account, diskFeedDictionary: DiskFeedDictionary) {
}
}

View File

@ -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 {

View File

@ -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) {
}
}

View File

@ -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 {