Give Feed a weak account rather than accountID.
This commit is contained in:
parent
b5b42b8df6
commit
679e6f6c0b
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Feed> {
|
||||
private static func feeds(with feedDictionaries: [DiskFeedDictionary], account: Account) -> Set<Feed> {
|
||||
|
||||
let feedArray = feedDictionaries.compactMap { Feed(accountID: accountID, dictionary: $0) }
|
||||
let feedArray = feedDictionaries.compactMap { Feed(account: account, dictionary: $0) }
|
||||
return Set(feedArray)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue