diff --git a/Frameworks/Data/OPML/Account+OPMLRepresentable.swift b/Frameworks/Account/Account+OPMLRepresentable.swift similarity index 100% rename from Frameworks/Data/OPML/Account+OPMLRepresentable.swift rename to Frameworks/Account/Account+OPMLRepresentable.swift diff --git a/Frameworks/Account/Account.xcodeproj/project.pbxproj b/Frameworks/Account/Account.xcodeproj/project.pbxproj index 11724b680..a9e0d6afe 100644 --- a/Frameworks/Account/Account.xcodeproj/project.pbxproj +++ b/Frameworks/Account/Account.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ 848935041F62485000CEBD24 /* AccountTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountTests.swift; sourceTree = ""; }; 848935061F62485000CEBD24 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 848935101F62486800CEBD24 /* Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = ""; }; + 848935201F62498B00CEBD24 /* Account+OPMLRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Account+OPMLRepresentable.swift"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -53,6 +54,7 @@ isa = PBXGroup; children = ( 848935101F62486800CEBD24 /* Account.swift */, + 848935201F62498B00CEBD24 /* Account+OPMLRepresentable.swift */, 848934FA1F62484F00CEBD24 /* Info.plist */, 848935031F62484F00CEBD24 /* AccountTests */, 848934F71F62484F00CEBD24 /* Products */, diff --git a/Frameworks/Database/AccountInfo.swift b/Frameworks/Data/AccountInfo.swift similarity index 90% rename from Frameworks/Database/AccountInfo.swift rename to Frameworks/Data/AccountInfo.swift index 9dac39660..499d84aca 100644 --- a/Frameworks/Database/AccountInfo.swift +++ b/Frameworks/Data/AccountInfo.swift @@ -7,8 +7,8 @@ // import Foundation -import RSCore -import RSDatabase + +public typealias AccountInfo = [String: AnyObject] // AccountInfo is a plist-compatible dictionary that’s stored as a binary plist in the database. diff --git a/Frameworks/Data/Article.swift b/Frameworks/Data/Article.swift index 5d587b5fe..45ab00113 100644 --- a/Frameworks/Data/Article.swift +++ b/Frameworks/Data/Article.swift @@ -27,6 +27,7 @@ public struct Article: Hashable { public let authors: Set? public let tags: Set? public let attachments: Set? + public let accountInfo: AccountInfo? public let hashValue: Int public init(accountID: String, articleID: String?, feedID: String, uniqueID: String, title: String?, contentHTML: String?, contentText: String?, url: String?, externalURL: String?, summary: String?, imageURL: String?, bannerImageURL: String?, datePublished: Date?, dateModified: Date?, authors: Set?, tags: Set?, attachments: Set?, accountInfo: AccountInfo?) { @@ -59,42 +60,10 @@ public struct Article: Hashable { self.hashValue = accountID.hashValue ^ self.articleID.hashValue } - public class func ==(lhs: Article, rhs: Article) -> Bool { + public static func ==(lhs: Article, rhs: Article) -> Bool { return lhs.hashValue == rhs.hashValue && lhs.articleID == rhs.articleID && lhs.accountID == rhs.accountID && lhs.feedID == rhs.feedID && lhs.uniqueID == rhs.uniqueID && lhs.title == rhs.title && lhs.contentHTML == rhs.contentHTML && lhs.url == rhs.url && lhs.externalURL == rhs.externalURL && lhs.summary == rhs.summary && lhs.imageURL == rhs.imageURL && lhs.bannerImageURL == rhs.bannerImageURL && lhs.datePublished == rhs.datePublished && lhs.authors == rhs.authors && lhs.tags == rhs.tags && lhs.attachments == rhs.attachments } } -public extension Article { - - // MARK: Main-thread only accessors. - - public var logicalDatePublished: Date? { - get { - assert(Thread.isMainThread) - return (datePublished ?? dateModified) ?? status?.dateArrived - } - } - - public var account: Account? { - get { - assert(Thread.isMainThread) - return Account.account(with: accountID) - } - } - - public var feed: Feed? { - get { - assert(Thread.isMainThread) - return account?.existingFeed(with: feedID) - } - } - - public var status: ArticleStatus? { - get { - assert(Thread.isMainThread) - return account?.status(with: articleID) - } - } -} diff --git a/Frameworks/Data/ArticleStatus.swift b/Frameworks/Data/ArticleStatus.swift index 0644caf44..b3413c86f 100644 --- a/Frameworks/Data/ArticleStatus.swift +++ b/Frameworks/Data/ArticleStatus.swift @@ -18,12 +18,13 @@ public enum ArticleStatusKey: String { public struct ArticleStatus: Hashable { public let articleID: String - public let read = false - public let starred = false - public let userDeleted = false public let dateArrived: Date - public let accountInfo: AccountInfo? public let hashValue: Int + + public var read = false + public var starred = false + public var userDeleted = false + public var accountInfo: AccountInfo? public init(articleID: String, read: Bool, starred: Bool, userDeleted: Bool, dateArrived: Date, accountInfo: AccountInfo?) { @@ -36,7 +37,7 @@ public struct ArticleStatus: Hashable { self.hashValue = articleID.hashValue } - public convenience init(articleID: String, dateArrived: Date) { + public init(articleID: String, dateArrived: Date) { self.init(articleID: articleID, read: false, starred: false, userDeleted: false, dateArrived: dateArrived, accountInfo: nil) } @@ -59,27 +60,27 @@ public struct ArticleStatus: Hashable { return false } -// public func setBoolStatus(_ status: Bool, forKey key: String) { -// -// if let articleStatusKey = ArticleStatusKey(rawValue: key) { -// switch articleStatusKey { -// case .read: -// read = status -// case .starred: -// starred = status -// case .userDeleted: -// userDeleted = status -// } -// } + public mutating func setBoolStatus(_ status: Bool, forKey key: String) { + + if let articleStatusKey = ArticleStatusKey(rawValue: key) { + switch articleStatusKey { + case .read: + read = status + case .starred: + starred = status + case .userDeleted: + userDeleted = status + } + } // else { // if accountInfo == nil { // accountInfo = AccountInfo() // } // accountInfo![key] = status // } -// } + } - public class func ==(lhs: ArticleStatus, rhs: ArticleStatus) -> Bool { + public static func ==(lhs: ArticleStatus, rhs: ArticleStatus) -> Bool { return lhs.hashValue == rhs.hashValue && lhs.articleID == rhs.articleID && lhs.dateArrived == rhs.dateArrived && lhs.read == rhs.read && lhs.starred == rhs.starred && lhs.userDeleted == rhs.userDeleted && lhs.accountInfo == rhs.accountInfo } diff --git a/Frameworks/Data/Data.xcodeproj/project.pbxproj b/Frameworks/Data/Data.xcodeproj/project.pbxproj index 38d087fe9..744cd53f6 100644 --- a/Frameworks/Data/Data.xcodeproj/project.pbxproj +++ b/Frameworks/Data/Data.xcodeproj/project.pbxproj @@ -19,7 +19,6 @@ 844BEE851F0AB4DB004AB7CD /* ArticleStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE841F0AB4DB004AB7CD /* ArticleStatus.swift */; }; 844BEE871F0AB4E3004AB7CD /* BatchUpdates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE861F0AB4E3004AB7CD /* BatchUpdates.swift */; }; 844BEE891F0AB4E7004AB7CD /* Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE881F0AB4E7004AB7CD /* Notifications.swift */; }; - 844BEE8F1F0AB4EF004AB7CD /* Account+OPMLRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE8B1F0AB4EF004AB7CD /* Account+OPMLRepresentable.swift */; }; 844BEE901F0AB4EF004AB7CD /* Feed+OPMLRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE8C1F0AB4EF004AB7CD /* Feed+OPMLRepresentable.swift */; }; 844BEE911F0AB4EF004AB7CD /* Folder+OPMLRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE8D1F0AB4EF004AB7CD /* Folder+OPMLRepresentable.swift */; }; 844BEE921F0AB4EF004AB7CD /* OPMLRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE8E1F0AB4EF004AB7CD /* OPMLRepresentable.swift */; }; @@ -27,6 +26,7 @@ 844BEE991F0AB4F8004AB7CD /* Container.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE951F0AB4F8004AB7CD /* Container.swift */; }; 844BEE9A1F0AB4F8004AB7CD /* DisplayNameProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE961F0AB4F8004AB7CD /* DisplayNameProvider.swift */; }; 844BEE9B1F0AB4F8004AB7CD /* UnreadCountProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE971F0AB4F8004AB7CD /* UnreadCountProvider.swift */; }; + 848935221F6249AC00CEBD24 /* AccountInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848935211F6249AC00CEBD24 /* AccountInfo.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -75,7 +75,6 @@ 844BEE841F0AB4DB004AB7CD /* ArticleStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArticleStatus.swift; sourceTree = ""; }; 844BEE861F0AB4E3004AB7CD /* BatchUpdates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BatchUpdates.swift; sourceTree = ""; }; 844BEE881F0AB4E7004AB7CD /* Notifications.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Notifications.swift; sourceTree = ""; }; - 844BEE8B1F0AB4EF004AB7CD /* Account+OPMLRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Account+OPMLRepresentable.swift"; sourceTree = ""; }; 844BEE8C1F0AB4EF004AB7CD /* Feed+OPMLRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Feed+OPMLRepresentable.swift"; sourceTree = ""; }; 844BEE8D1F0AB4EF004AB7CD /* Folder+OPMLRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Folder+OPMLRepresentable.swift"; sourceTree = ""; }; 844BEE8E1F0AB4EF004AB7CD /* OPMLRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OPMLRepresentable.swift; sourceTree = ""; }; @@ -84,6 +83,7 @@ 844BEE961F0AB4F8004AB7CD /* DisplayNameProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DisplayNameProvider.swift; sourceTree = ""; }; 844BEE971F0AB4F8004AB7CD /* UnreadCountProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnreadCountProvider.swift; sourceTree = ""; }; 844BEE9C1F0AB512004AB7CD /* RSCore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSCore.xcodeproj; path = ../RSCore/RSCore.xcodeproj; sourceTree = ""; }; + 848935211F6249AC00CEBD24 /* AccountInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountInfo.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -115,6 +115,7 @@ 844BEE801F0AB4D0004AB7CD /* Author.swift */, 844BEE821F0AB4D6004AB7CD /* Attachment.swift */, 844BEE841F0AB4DB004AB7CD /* ArticleStatus.swift */, + 848935211F6249AC00CEBD24 /* AccountInfo.swift */, 840405C91F1A8E4300DF0296 /* DatabaseID.swift */, 844BEE861F0AB4E3004AB7CD /* BatchUpdates.swift */, 844BEE881F0AB4E7004AB7CD /* Notifications.swift */, @@ -148,7 +149,6 @@ 844BEE8A1F0AB4EF004AB7CD /* OPML */ = { isa = PBXGroup; children = ( - 844BEE8B1F0AB4EF004AB7CD /* Account+OPMLRepresentable.swift */, 844BEE8C1F0AB4EF004AB7CD /* Feed+OPMLRepresentable.swift */, 844BEE8D1F0AB4EF004AB7CD /* Folder+OPMLRepresentable.swift */, 844BEE8E1F0AB4EF004AB7CD /* OPMLRepresentable.swift */, @@ -332,8 +332,8 @@ 844BEE7F1F0AB4CA004AB7CD /* Article.swift in Sources */, 844BEE7D1F0AB4C4004AB7CD /* Feed.swift in Sources */, 844BEE891F0AB4E7004AB7CD /* Notifications.swift in Sources */, + 848935221F6249AC00CEBD24 /* AccountInfo.swift in Sources */, 844BEE9A1F0AB4F8004AB7CD /* DisplayNameProvider.swift in Sources */, - 844BEE8F1F0AB4EF004AB7CD /* Account+OPMLRepresentable.swift in Sources */, 844BEE991F0AB4F8004AB7CD /* Container.swift in Sources */, 844BEE7B1F0AB4BE004AB7CD /* Folder.swift in Sources */, 844BEE981F0AB4F8004AB7CD /* AccountDelegate.swift in Sources */, diff --git a/Frameworks/Data/Feed.swift b/Frameworks/Data/Feed.swift index dc0c89a9b..6506d5abc 100644 --- a/Frameworks/Data/Feed.swift +++ b/Frameworks/Data/Feed.swift @@ -11,7 +11,7 @@ import RSCore public final class Feed: UnreadCountProvider, DisplayNameProvider, Hashable { - public let account: Account + public let accountID: String public let url: String public let feedID: String public var homePageURL: String? @@ -35,12 +35,12 @@ public final class Feed: UnreadCountProvider, DisplayNameProvider, Hashable { } } - public init(account: Account, url: String, feedID: String) { + public init(accountID: String, url: String, feedID: String) { - self.account = account + self.accountID = accountID self.url = url self.feedID = feedID - self.hashValue = account.hashValue ^ url.hashValue ^ feedID.hashValue + self.hashValue = accountID.hashValue ^ url.hashValue ^ feedID.hashValue } public func updateUnreadCount() { diff --git a/Frameworks/Data/Folder.swift b/Frameworks/Data/Folder.swift index 09e78f22d..9c3a82098 100644 --- a/Frameworks/Data/Folder.swift +++ b/Frameworks/Data/Folder.swift @@ -10,13 +10,13 @@ import Foundation public final class Folder: UnreadCountProvider { - public let account: Account + public let accountID: String public var nameForDisplay: String var childObjects = [AnyObject]() - init(account: Account, nameForDisplay: String) { + init(accountID: String, nameForDisplay: String) { - self.account = account + self.accountID = accountID self.nameForDisplay = nameForDisplay NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) diff --git a/Frameworks/Database/Database.xcodeproj/project.pbxproj b/Frameworks/Database/Database.xcodeproj/project.pbxproj index 500b63d64..57f35c695 100644 --- a/Frameworks/Database/Database.xcodeproj/project.pbxproj +++ b/Frameworks/Database/Database.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ 844BEE461F0AB3AB004AB7CD /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE451F0AB3AB004AB7CD /* DatabaseTests.swift */; }; 844ECFC91F5B4F0E005E405A /* ParsedItem+Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844ECFC81F5B4F0E005E405A /* ParsedItem+Database.swift */; }; 845580671F0AEBCD003CCFA1 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845580661F0AEBCD003CCFA1 /* Constants.swift */; }; - 845580721F0AEE49003CCFA1 /* AccountInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845580711F0AEE49003CCFA1 /* AccountInfo.swift */; }; 845580761F0AF670003CCFA1 /* Article+Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845580751F0AF670003CCFA1 /* Article+Database.swift */; }; 845580781F0AF678003CCFA1 /* Folder+Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845580771F0AF678003CCFA1 /* Folder+Database.swift */; }; 8455807A1F0AF67D003CCFA1 /* ArticleStatus+Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845580791F0AF67D003CCFA1 /* ArticleStatus+Database.swift */; }; @@ -121,7 +120,6 @@ 844BEE471F0AB3AB004AB7CD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 844ECFC81F5B4F0E005E405A /* ParsedItem+Database.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "ParsedItem+Database.swift"; path = "Extensions/ParsedItem+Database.swift"; sourceTree = ""; }; 845580661F0AEBCD003CCFA1 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = ""; }; - 845580711F0AEE49003CCFA1 /* AccountInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountInfo.swift; sourceTree = ""; }; 845580751F0AF670003CCFA1 /* Article+Database.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Article+Database.swift"; path = "Extensions/Article+Database.swift"; sourceTree = ""; }; 845580771F0AF678003CCFA1 /* Folder+Database.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Folder+Database.swift"; path = "Extensions/Folder+Database.swift"; sourceTree = ""; }; 845580791F0AF67D003CCFA1 /* ArticleStatus+Database.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "ArticleStatus+Database.swift"; path = "Extensions/ArticleStatus+Database.swift"; sourceTree = ""; }; @@ -224,7 +222,6 @@ 8455807B1F0C0DBD003CCFA1 /* Attachment+Database.swift */, 84D0DEA01F4A429800073503 /* String+Database.swift */, 844ECFC81F5B4F0E005E405A /* ParsedItem+Database.swift */, - 845580711F0AEE49003CCFA1 /* AccountInfo.swift */, ); name = Extensions; sourceTree = ""; @@ -488,7 +485,6 @@ 84E156EC1F0AB80E00F8CC05 /* ArticlesTable.swift in Sources */, 84E156EE1F0AB81400F8CC05 /* StatusesTable.swift in Sources */, 844ECFC91F5B4F0E005E405A /* ParsedItem+Database.swift in Sources */, - 845580721F0AEE49003CCFA1 /* AccountInfo.swift in Sources */, 84E156EA1F0AB80500F8CC05 /* Database.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0;