diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index cd0d20a0a..7aa3f7c4c 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -270,7 +270,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, return feed } - let feed = Feed(accountID: accountID, url: url, feedID: url) + let feed = Feed(account: self, url: url, feedID: url) feed.name = name feed.editedName = editedName @@ -456,7 +456,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, @objc func feedSettingDidChange(_ note: Notification) { - if let feed = note.object as? Feed, let feedAccount = feed.account, feedAccount === self { + if let feed = note.object as? Feed, feed.account === self { dirty = true } } @@ -540,7 +540,7 @@ private extension Account { func object(with diskObject: [String: Any]) -> AnyObject? { if Feed.isFeedDictionary(diskObject) { - return Feed(accountID: accountID, dictionary: diskObject) + return Feed(account: self, dictionary: diskObject) } return Folder(account: self, dictionary: diskObject) } @@ -635,7 +635,7 @@ private extension Account { func createFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> Feed { - let feed = Feed(accountID: accountID, url: opmlFeedSpecifier.feedURL, feedID: opmlFeedSpecifier.feedURL) + let feed = Feed(account: self, url: opmlFeedSpecifier.feedURL, feedID: opmlFeedSpecifier.feedURL) feed.editedName = opmlFeedSpecifier.title return feed } diff --git a/Frameworks/Account/DataExtensions.swift b/Frameworks/Account/DataExtensions.swift index 0bce67963..8d19eb1eb 100644 --- a/Frameworks/Account/DataExtensions.swift +++ b/Frameworks/Account/DataExtensions.swift @@ -17,10 +17,6 @@ public extension Notification.Name { public extension Feed { - public var account: Account? { - return AccountManager.shared.existingAccount(with: accountID) - } - public func takeSettings(from parsedFeed: ParsedFeed) { var didChangeAtLeastOneSetting = false diff --git a/Frameworks/Account/Feed.swift b/Frameworks/Account/Feed.swift index 7391a72ee..92210e806 100644 --- a/Frameworks/Account/Feed.swift +++ b/Frameworks/Account/Feed.swift @@ -14,7 +14,7 @@ import RSDatabase public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { - public let accountID: String + public weak var account: Account? public let url: String public let feedID: String @@ -69,17 +69,16 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { } } - private lazy var settingsTable: ODBRawValueTable? = { - return account?.settingsTableForFeed(feedID: feedID) - }() + private let settingsTable: ODBRawValueTable // MARK: - Init - public init(accountID: String, url: String, feedID: String) { + public init(account: Account, url: String, feedID: String) { - self.accountID = accountID + self.account = account self.url = url self.feedID = feedID + self.settingsTable = account.settingsTableForFeed(feedID: feedID)! } // MARK: - Disk Dictionary @@ -97,14 +96,14 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { static let contentHash = "contentHash" } - convenience public init?(accountID: String, dictionary: [String: Any]) { + convenience public init?(account: Account, dictionary: [String: Any]) { guard let url = dictionary[Key.url] as? String else { return nil } let feedID = dictionary[Key.feedID] as? String ?? url - self.init(accountID: accountID, url: url, feedID: feedID) + self.init(account: account, url: url, feedID: feedID) self.homePageURL = dictionary[Key.homePageURL] as? String self.iconURL = dictionary[Key.iconURL] as? String self.faviconURL = dictionary[Key.faviconURL] as? String diff --git a/Frameworks/Account/Folder.swift b/Frameworks/Account/Folder.swift index 7f91adc41..5e0e940b6 100644 --- a/Frameworks/Account/Folder.swift +++ b/Frameworks/Account/Folder.swift @@ -198,7 +198,7 @@ private extension Folder { for diskObject in diskObjects { if Feed.isFeedDictionary(diskObject) { - if let feed = Feed(accountID: account.accountID, dictionary: diskObject) { + if let feed = Feed(account: account, dictionary: diskObject) { feeds.insert(feed) } } diff --git a/Importers/DefaultFeedsImporter.swift b/Importers/DefaultFeedsImporter.swift index b25c96d5d..839e8f2ee 100644 --- a/Importers/DefaultFeedsImporter.swift +++ b/Importers/DefaultFeedsImporter.swift @@ -42,7 +42,7 @@ struct FeedsImporter { static func importFeeds(_ feedDictionaries: [DiskFeedDictionary], account: Account) { - let feedsToImport = feeds(with: feedDictionaries, accountID: account.accountID) + let feedsToImport = feeds(with: feedDictionaries, account: account) BatchUpdate.shared.perform { for feed in feedsToImport { @@ -54,9 +54,9 @@ struct FeedsImporter { account.dirty = true } - private static func feeds(with feedDictionaries: [DiskFeedDictionary], accountID: String) -> Set { + private static func feeds(with feedDictionaries: [DiskFeedDictionary], account: Account) -> Set { - let feedArray = feedDictionaries.compactMap { Feed(accountID: accountID, dictionary: $0) } + let feedArray = feedDictionaries.compactMap { Feed(account: account, dictionary: $0) } return Set(feedArray) } }