diff --git a/Evergreen.xcodeproj/project.pbxproj b/Evergreen.xcodeproj/project.pbxproj index 7a1e61038..30e25efed 100644 --- a/Evergreen.xcodeproj/project.pbxproj +++ b/Evergreen.xcodeproj/project.pbxproj @@ -1160,6 +1160,7 @@ 849A97651ED9EB96007D329B /* SidebarTreeControllerDelegate.swift in Sources */, 849A97671ED9EB96007D329B /* UnreadCountView.swift in Sources */, 849A975B1ED9EB0D007D329B /* ArticleUtilities.swift in Sources */, + 849A975C1ED9EB0D007D329B /* DefaultFeedsImporter.swift in Sources */, 849A97891ED9ECEF007D329B /* ArticleStyle.swift in Sources */, 849A978A1ED9ECEF007D329B /* ArticleStylesManager.swift in Sources */, 849A97791ED9EC04007D329B /* TimelineStringUtilities.swift in Sources */, @@ -1172,7 +1173,6 @@ 849A976E1ED9EBC8007D329B /* TimelineViewController.swift in Sources */, 849A978D1ED9EE4D007D329B /* FeedListWindowController.swift in Sources */, 849A97771ED9EC04007D329B /* TimelineCellData.swift in Sources */, - 849A975C1ED9EB0D007D329B /* DefaultFeedsImporter.swift in Sources */, 849A97781ED9EC04007D329B /* TimelineCellLayout.swift in Sources */, 849A976C1ED9EBC8007D329B /* TimelineTableRowView.swift in Sources */, 849A977B1ED9EC04007D329B /* UnreadIndicatorView.swift in Sources */, diff --git a/Evergreen/AppDelegate.swift b/Evergreen/AppDelegate.swift index f453f8bd1..049bf9242 100644 --- a/Evergreen/AppDelegate.swift +++ b/Evergreen/AppDelegate.swift @@ -48,7 +48,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations { let isFirstRun = AppDefaults.shared.isFirstRun let localAccount = AccountManager.shared.localAccount - importDefaultFeedsIfNeeded(isFirstRun, account: localAccount) + DefaultFeedsImporter.importIfNeeded(isFirstRun, account: localAccount) currentTheme = themeLoader.defaultTheme diff --git a/Evergreen/Data/DefaultFeedsImporter.swift b/Evergreen/Data/DefaultFeedsImporter.swift index 8b075ff5f..c8ca3f26f 100644 --- a/Evergreen/Data/DefaultFeedsImporter.swift +++ b/Evergreen/Data/DefaultFeedsImporter.swift @@ -10,7 +10,7 @@ import Foundation import Data import Account -typealias DiskFeedDictionary = [String: String] +typealias DiskFeedDictionary = [String: Any] struct DefaultFeedsImporter { @@ -44,24 +44,20 @@ struct DefaultFeedsImporter { struct FeedsImporter { - func importFeeds(_ feedDictionaries: [DiskFeedDictionary], account: Account) { + static func importFeeds(_ feedDictionaries: [DiskFeedDictionary], account: Account) { - let feedsToImport = feeds(with: feedDictionaries) - feedsToImport.forEach(account.addItem) + let feedsToImport = feeds(with: feedDictionaries, accountID: account.accountID) + for feed in feedsToImport { + if !account.hasFeed(with: feed.feedID) { + let _ = account.addFeed(feed, to: nil) + } + } } - private func feeds(with feedDictionaries: [DiskFeedDictionary]) -> Set { + private static func feeds(with feedDictionaries: [DiskFeedDictionary], accountID: String) -> Set { - let feeds = Set(feedDictionaries.map { Feed(account: account, diskFeedDictionary: $0) }) + let feeds = Set(feedDictionaries.map { Feed(accountID: accountID, dictionary: $0) }) return feeds } } -private extension Feed { - - init?(account: Account, diskFeedDictionary: DiskFeedDictionary) { - - - } -} - diff --git a/Evergreen/Preferences/PreferencesWindowController.swift b/Evergreen/Preferences/PreferencesWindowController.swift index 3ec51ca65..270108542 100644 --- a/Evergreen/Preferences/PreferencesWindowController.swift +++ b/Evergreen/Preferences/PreferencesWindowController.swift @@ -63,7 +63,7 @@ class PreferencesWindowController : NSWindowController, NSToolbarDelegate { func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? { - guard let toolbarItemSpec = toolbarItemSpecs.first(where: { $0.identifier.rawValue == itemIdentifier }) else { + guard let toolbarItemSpec = toolbarItemSpecs.first(where: { $0.identifier.rawValue == itemIdentifier.rawValue }) else { return nil } diff --git a/Evergreen/Resources/DefaultFeeds.plist b/Evergreen/Resources/DefaultFeeds.plist index 74d6642ee..e72db4a21 100644 --- a/Evergreen/Resources/DefaultFeeds.plist +++ b/Evergreen/Resources/DefaultFeeds.plist @@ -7,13 +7,13 @@ By Brent Simmons, Evergreen developer editedName Inessential - home + homePageURL http://inessential.com/ url http://inessential.com/xml/rss.xml - home + homePageURL http://daringfireball.net/ editedName Daring Fireball @@ -21,7 +21,7 @@ http://daringfireball.net/feeds/main - home + homePageURL https://www.natashatherobot.com/ editedName Natasha the Robot @@ -29,7 +29,7 @@ https://www.natashatherobot.com/feed/ - home + homePageURL http://www.imore.com/ editedName iMore @@ -37,7 +37,7 @@ http://www.imore.com/rss.xml - home + homePageURL http://becky.coffee/ note iOS developer & corgi enthusiast @@ -47,7 +47,7 @@ http://beckyhansmeyer.com/feed/ - home + homePageURL http://shapeof.com/ note By Gus Mueller, Acorn developer @@ -57,7 +57,7 @@ http://shapeof.com/rss.xml - home + homePageURL http://redqueencoder.com/ note Janie Clayton @@ -67,7 +67,7 @@ http://redqueencoder.com/feed/ - home + homePageURL https://medium.com/@jaimeejaimee editedName jaimeejaimee @@ -77,7 +77,7 @@ https://medium.com/feed/@jaimeejaimee - home + homePageURL http://sixcolors.com note By Jason Snell & friends @@ -87,7 +87,7 @@ http://feedpress.me/sixcolors - home + homePageURL http://www.loopinsight.com/ note Jim Dalrymple and Dave Mark @@ -97,7 +97,7 @@ http://www.loopinsight.com/feed/ - home + homePageURL http://katiefloyd.com/ editedName Katie Floyd @@ -105,7 +105,7 @@ http://feed.katiefloyd.com/ - home + homePageURL http://ashleynh.me/ editedName Ashley Nelson-Hornstein @@ -113,7 +113,7 @@ http://blog.ashleynh.me/rss/ - home + homePageURL https://ranchero.com/evergreen/ editedName Evergreen News @@ -121,7 +121,7 @@ https://ranchero.com/evergreen/feed.json - home + homePageURL http://scripting.com/ editedName Scripting News @@ -131,7 +131,7 @@ http://scripting.com/rss.xml - home + homePageURL http://ericasadun.com/ editedName Erica Sadun @@ -141,7 +141,7 @@ http://ericasadun.com/feed/ - home + homePageURL http://onefoottsunami.com/ editedName One Foot Tsunami diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 45c08f534..00dbed424 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -98,12 +98,12 @@ public final class Account: DisplayNameProvider, Hashable { return true // TODO } - public func canAddFolder(_ folder: Folder, to folder: Folder?) -> Bool { + public func canAddFolder(_ folder: Folder, to containingFolder: Folder?) -> Bool { return false // TODO } - public func addFolder(_ folder: Folder, to folder: Folder?) -> Bool { + public func addFolder(_ folder: Folder, to containingFolder: Folder?) -> Bool { return false // TODO } diff --git a/Frameworks/Account/Container/Container.swift b/Frameworks/Account/Container/Container.swift index 28526518e..ba1a316a6 100644 --- a/Frameworks/Account/Container/Container.swift +++ b/Frameworks/Account/Container/Container.swift @@ -24,6 +24,7 @@ public protocol Container { func flattenedFeeds() -> Set func existingFeed(with feedID: String) -> Feed? func existingFeed(withURL url: String) -> Feed? + func hasFeed(with feedID: String) -> Bool func hasFeed(withURL url: String) -> Bool func isChild(_ obj: AnyObject) -> Bool @@ -65,6 +66,14 @@ public extension Container { return foundObject as! Feed? } + func hasFeed(with feedID: String) -> Bool { + + if let _ = existingFeed(with: feedID) { + return true + } + return false + } + func hasFeed(withURL url: String) -> Bool { if let _ = existingFeed(withURL: url) { diff --git a/Frameworks/Account/Local/LocalAccountRefresher.swift b/Frameworks/Account/Local/LocalAccountRefresher.swift index 90eae2708..c0ffb71eb 100644 --- a/Frameworks/Account/Local/LocalAccountRefresher.swift +++ b/Frameworks/Account/Local/LocalAccountRefresher.swift @@ -42,7 +42,7 @@ final class LocalAccountRefresher: DownloadSessionDelegate { } let request = NSMutableURLRequest(url: url) - if let conditionalGetInfo = feed.conditionalGetInfo, !conditionalGetInfo.isEmpty { + if let conditionalGetInfo = feed.conditionalGetInfo { conditionalGetInfo.addRequestHeadersToURLRequest(request) } @@ -75,10 +75,7 @@ final class LocalAccountRefresher: DownloadSessionDelegate { account.update(feed, with: parsedFeed) { if let httpResponse = response as? HTTPURLResponse { - let conditionalGetInfo = HTTPConditionalGetInfo(urlResponse: httpResponse) - if !conditionalGetInfo.isEmpty || feed.conditionalGetInfo != nil { - feed.conditionalGetInfo = conditionalGetInfo - } + feed.conditionalGetInfo = HTTPConditionalGetInfo(urlResponse: httpResponse) } feed.contentHash = dataHash diff --git a/Frameworks/RSWeb/RSWeb/HTTPConditionalGetInfo.swift b/Frameworks/RSWeb/RSWeb/HTTPConditionalGetInfo.swift index 49569f127..0c04fd796 100755 --- a/Frameworks/RSWeb/RSWeb/HTTPConditionalGetInfo.swift +++ b/Frameworks/RSWeb/RSWeb/HTTPConditionalGetInfo.swift @@ -13,9 +13,16 @@ public struct HTTPConditionalGetInfo { public let lastModified: String? public let etag: String? - public var isEmpty: Bool { + public var dictionary: [String: String] { get { - return lastModified == nil && etag == nil + var d = [String: String]() + if let lastModified = lastModified { + d[HTTPResponseHeader.lastModified] = lastModified + } + if let etag = etag { + d[HTTPResponseHeader.etag] = etag + } + return d } } @@ -36,19 +43,6 @@ public struct HTTPConditionalGetInfo { self.init(lastModified: lastModified, etag: etag) } - public var dictionary: [String: String] { - get { - var d = [String: String]() - if let lastModified = lastModified { - d[HTTPResponseHeader.lastModified] = lastModified - } - if let etag = etag { - d[HTTPResponseHeader.etag] = etag - } - return d - } - } - public init?(dictionary: [String: String]) { self.init(lastModified: dictionary[HTTPResponseHeader.lastModified], etag: dictionary[HTTPResponseHeader.etag])