Rename AccountSettings to AccountMetadata to show that more than settings are stored in it and that it is analogous to FeedMetadata

This commit is contained in:
Maurice Parker 2019-05-05 07:49:59 -05:00
parent 6e7477fd89
commit 35160aaf75
7 changed files with 60 additions and 55 deletions

View File

@ -57,12 +57,12 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
public var name: String? { public var name: String? {
get { get {
return settings.name return metadata.name
} }
set { set {
let currentNameForDisplay = nameForDisplay let currentNameForDisplay = nameForDisplay
if newValue != settings.name { if newValue != metadata.name {
settings.name = newValue metadata.name = newValue
if currentNameForDisplay != nameForDisplay { if currentNameForDisplay != nameForDisplay {
postDisplayNameDidChangeNotification() postDisplayNameDidChangeNotification()
} }
@ -73,11 +73,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
public var isActive: Bool { public var isActive: Bool {
get { get {
return settings.isActive return metadata.isActive
} }
set { set {
if newValue != settings.isActive { if newValue != metadata.isActive {
settings.isActive = newValue metadata.isActive = newValue
NotificationCenter.default.post(name: .AccountStateDidChange, object: self, userInfo: nil) NotificationCenter.default.post(name: .AccountStateDidChange, object: self, userInfo: nil)
} }
} }
@ -96,11 +96,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
var username: String? { var username: String? {
get { get {
return settings.username return metadata.username
} }
set { set {
if newValue != settings.username { if newValue != metadata.username {
settings.username = newValue metadata.username = newValue
} }
} }
} }
@ -119,11 +119,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
private var _flattenedFeeds = Set<Feed>() private var _flattenedFeeds = Set<Feed>()
private var flattenedFeedsNeedUpdate = true private var flattenedFeedsNeedUpdate = true
private let settingsPath: String private let metadataPath: String
private var settings = AccountSettings() private var metadata = AccountMetadata()
private var settingsDirty = false { private var metadataDirty = false {
didSet { didSet {
queueSaveSettingsIfNeeded() queueSaveAccountMetadatafNeeded()
} }
} }
@ -132,7 +132,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
private var feedMetadata = FeedMetadataDictionary() private var feedMetadata = FeedMetadataDictionary()
private var feedMetadataDirty = false { private var feedMetadataDirty = false {
didSet { didSet {
queueSaveMetadataIfNeeded() queueSaveFeedMetadataIfNeeded()
} }
} }
@ -195,7 +195,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
self.database = ArticlesDatabase(databaseFilePath: databaseFilePath, accountID: accountID) self.database = ArticlesDatabase(databaseFilePath: databaseFilePath, accountID: accountID)
self.feedMetadataPath = (dataFolder as NSString).appendingPathComponent("FeedMetadata.plist") self.feedMetadataPath = (dataFolder as NSString).appendingPathComponent("FeedMetadata.plist")
self.settingsPath = (dataFolder as NSString).appendingPathComponent("Settings.plist") self.metadataPath = (dataFolder as NSString).appendingPathComponent("Settings.plist")
switch type { switch type {
case .onMyMac: case .onMyMac:
@ -388,8 +388,8 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
// For syncing, this may need to be an async method with a callback, // For syncing, this may need to be an async method with a callback,
// since it will likely need to call the server. // since it will likely need to call the server.
let feedMetadata = metadata(feedID: url) let metadata = feedMetadata(feedID: url)
let feed = Feed(account: self, url: url, feedID: url, metadata: feedMetadata) let feed = Feed(account: self, url: url, feedID: url, metadata: metadata)
if let name = name, feed.name == nil { if let name = name, feed.name == nil {
feed.name = name feed.name = name
} }
@ -671,15 +671,15 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
} }
@objc func saveMetadataIfNeeded() { @objc func saveFeedMetadataIfNeeded() {
if feedMetadataDirty { if feedMetadataDirty {
saveFeedMetadata() saveFeedMetadata()
} }
} }
@objc func saveSettingsIfNeeded() { @objc func saveAccountMetadataIfNeeded() {
if settingsDirty { if metadataDirty {
saveSettings() saveAccountMetadata()
} }
} }
@ -697,11 +697,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
} }
// MARK: - AccountSettingsDelegate // MARK: - AccountMetadataDelegate
extension Account: AccountSettingsDelegate { extension Account: AccountMetadataDelegate {
func valueDidChange(_ accountSettings: AccountSettings, key: AccountSettings.CodingKeys) { func valueDidChange(_ accountMetadata: AccountMetadata, key: AccountMetadata.CodingKeys) {
settingsDirty = true metadataDirty = true
} }
} }
@ -727,20 +727,20 @@ private extension Account {
} }
func pullObjectsFromDisk() { func pullObjectsFromDisk() {
importSettings() importAccountMetadata()
importFeedMetadata() importFeedMetadata()
importOPMLFile(path: opmlFilePath) importOPMLFile(path: opmlFilePath)
} }
func importSettings() { func importAccountMetadata() {
let url = URL(fileURLWithPath: settingsPath) let url = URL(fileURLWithPath: metadataPath)
guard let data = try? Data(contentsOf: url) else { guard let data = try? Data(contentsOf: url) else {
settings.delegate = self metadata.delegate = self
return return
} }
let decoder = PropertyListDecoder() let decoder = PropertyListDecoder()
settings = (try? decoder.decode(AccountSettings.self, from: data)) ?? AccountSettings() metadata = (try? decoder.decode(AccountMetadata.self, from: data)) ?? AccountMetadata()
settings.delegate = self metadata.delegate = self
} }
func importFeedMetadata() { func importFeedMetadata() {
@ -808,8 +808,8 @@ private extension Account {
} }
} }
func queueSaveMetadataIfNeeded() { func queueSaveFeedMetadataIfNeeded() {
Account.saveQueue.add(self, #selector(saveMetadataIfNeeded)) Account.saveQueue.add(self, #selector(saveFeedMetadataIfNeeded))
} }
private func metadataForOnlySubscribedToFeeds() -> FeedMetadataDictionary { private func metadataForOnlySubscribedToFeeds() -> FeedMetadataDictionary {
@ -835,18 +835,18 @@ private extension Account {
} }
} }
func queueSaveSettingsIfNeeded() { func queueSaveAccountMetadatafNeeded() {
Account.saveQueue.add(self, #selector(saveSettingsIfNeeded)) Account.saveQueue.add(self, #selector(saveAccountMetadataIfNeeded))
} }
func saveSettings() { func saveAccountMetadata() {
settingsDirty = false metadataDirty = false
let encoder = PropertyListEncoder() let encoder = PropertyListEncoder()
encoder.outputFormat = .binary encoder.outputFormat = .binary
let url = URL(fileURLWithPath: settingsPath) let url = URL(fileURLWithPath: metadataPath)
do { do {
let data = try encoder.encode(settings) let data = try encoder.encode(metadata)
try data.write(to: url) try data.write(to: url)
} }
catch { catch {
@ -859,7 +859,7 @@ private extension Account {
private extension Account { private extension Account {
func metadata(feedID: String) -> FeedMetadata { func feedMetadata(feedID: String) -> FeedMetadata {
if let d = feedMetadata[feedID] { if let d = feedMetadata[feedID] {
assert(d.delegate === self) assert(d.delegate === self)
return d return d
@ -894,8 +894,8 @@ private extension Account {
func createFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> Feed { func createFeed(with opmlFeedSpecifier: RSOPMLFeedSpecifier) -> Feed {
let feedID = opmlFeedSpecifier.feedURL let feedID = opmlFeedSpecifier.feedURL
let feedMetadata = metadata(feedID: feedID) let metadata = feedMetadata(feedID: feedID)
let feed = Feed(account: self, url: opmlFeedSpecifier.feedURL, feedID: feedID, metadata: feedMetadata) let feed = Feed(account: self, url: opmlFeedSpecifier.feedURL, feedID: feedID, metadata: metadata)
if let feedTitle = opmlFeedSpecifier.title { if let feedTitle = opmlFeedSpecifier.title {
if feed.name == nil { if feed.name == nil {
feed.name = feedTitle feed.name = feedTitle

View File

@ -38,7 +38,7 @@
84D09623217418DC00D77525 /* FeedbinTagging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D09622217418DC00D77525 /* FeedbinTagging.swift */; }; 84D09623217418DC00D77525 /* FeedbinTagging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D09622217418DC00D77525 /* FeedbinTagging.swift */; };
84D0962521741B8500D77525 /* FeedbinSavedSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D0962421741B8500D77525 /* FeedbinSavedSearch.swift */; }; 84D0962521741B8500D77525 /* FeedbinSavedSearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D0962421741B8500D77525 /* FeedbinSavedSearch.swift */; };
84EAC4822148CC6300F154AB /* RSDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84EAC4812148CC6300F154AB /* RSDatabase.framework */; }; 84EAC4822148CC6300F154AB /* RSDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84EAC4812148CC6300F154AB /* RSDatabase.framework */; };
84F1F06E2243524700DA0616 /* AccountSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AF4EA3222CFDD100F6A800 /* AccountSettings.swift */; }; 84F1F06E2243524700DA0616 /* AccountMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AF4EA3222CFDD100F6A800 /* AccountMetadata.swift */; };
84F73CF1202788D90000BCEF /* ArticleFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F73CF0202788D80000BCEF /* ArticleFetcher.swift */; }; 84F73CF1202788D90000BCEF /* ArticleFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F73CF0202788D80000BCEF /* ArticleFetcher.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@ -113,7 +113,7 @@
848935041F62485000CEBD24 /* AccountTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountTests.swift; sourceTree = "<group>"; }; 848935041F62485000CEBD24 /* AccountTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountTests.swift; sourceTree = "<group>"; };
848935061F62485000CEBD24 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 848935061F62485000CEBD24 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
848935101F62486800CEBD24 /* Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = "<group>"; }; 848935101F62486800CEBD24 /* Account.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Account.swift; sourceTree = "<group>"; };
84AF4EA3222CFDD100F6A800 /* AccountSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSettings.swift; sourceTree = "<group>"; }; 84AF4EA3222CFDD100F6A800 /* AccountMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountMetadata.swift; sourceTree = "<group>"; };
84B2D4CE2238C13D00498ADA /* FeedMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedMetadata.swift; sourceTree = "<group>"; }; 84B2D4CE2238C13D00498ADA /* FeedMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedMetadata.swift; sourceTree = "<group>"; };
84B99C9E1FAE8D3200ECDEDB /* ContainerPath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerPath.swift; sourceTree = "<group>"; }; 84B99C9E1FAE8D3200ECDEDB /* ContainerPath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContainerPath.swift; sourceTree = "<group>"; };
84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CombinedRefreshProgress.swift; sourceTree = "<group>"; }; 84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CombinedRefreshProgress.swift; sourceTree = "<group>"; };
@ -217,7 +217,7 @@
848935101F62486800CEBD24 /* Account.swift */, 848935101F62486800CEBD24 /* Account.swift */,
841974241F6DDCE4006346C4 /* AccountDelegate.swift */, 841974241F6DDCE4006346C4 /* AccountDelegate.swift */,
846E77531F6F00E300A165E2 /* AccountManager.swift */, 846E77531F6F00E300A165E2 /* AccountManager.swift */,
84AF4EA3222CFDD100F6A800 /* AccountSettings.swift */, 84AF4EA3222CFDD100F6A800 /* AccountMetadata.swift */,
84F73CF0202788D80000BCEF /* ArticleFetcher.swift */, 84F73CF0202788D80000BCEF /* ArticleFetcher.swift */,
84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */, 84C365491F899F3B001EC85C /* CombinedRefreshProgress.swift */,
8419740D1F6DD25F006346C4 /* Container.swift */, 8419740D1F6DD25F006346C4 /* Container.swift */,
@ -449,7 +449,7 @@
841974011F6DD1EC006346C4 /* Folder.swift in Sources */, 841974011F6DD1EC006346C4 /* Folder.swift in Sources */,
846E774F1F6EF9C000A165E2 /* LocalAccountDelegate.swift in Sources */, 846E774F1F6EF9C000A165E2 /* LocalAccountDelegate.swift in Sources */,
844B297F210CE37E004020B3 /* UnreadCountProvider.swift in Sources */, 844B297F210CE37E004020B3 /* UnreadCountProvider.swift in Sources */,
84F1F06E2243524700DA0616 /* AccountSettings.swift in Sources */, 84F1F06E2243524700DA0616 /* AccountMetadata.swift in Sources */,
84245C851FDDD8CB0074AFBB /* FeedbinFeed.swift in Sources */, 84245C851FDDD8CB0074AFBB /* FeedbinFeed.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;

View File

@ -15,7 +15,7 @@ protocol AccountDelegate {
var supportsSubFolders: Bool { get } var supportsSubFolders: Bool { get }
var server: String? { get } var server: String? { get }
var credentials: Credentials? { get set } var credentials: Credentials? { get set }
var settings: AccountSettings? { get set } var accountMetadata: AccountMetadata? { get set }
var refreshProgress: DownloadProgress { get } var refreshProgress: DownloadProgress { get }

View File

@ -1,5 +1,5 @@
// //
// AccountSettings.swift // AccountMetadata.swift
// Account // Account
// //
// Created by Brent Simmons on 3/3/19. // Created by Brent Simmons on 3/3/19.
@ -8,11 +8,11 @@
import Foundation import Foundation
protocol AccountSettingsDelegate: class { protocol AccountMetadataDelegate: class {
func valueDidChange(_ accountSettings: AccountSettings, key: AccountSettings.CodingKeys) func valueDidChange(_ accountMetadata: AccountMetadata, key: AccountMetadata.CodingKeys)
} }
final class AccountSettings: Codable { final class AccountMetadata: Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case name case name
@ -44,7 +44,7 @@ final class AccountSettings: Codable {
} }
} }
weak var delegate: AccountSettingsDelegate? weak var delegate: AccountMetadataDelegate?
func valueDidChange(_ key: CodingKeys) { func valueDidChange(_ key: CodingKeys) {
delegate?.valueDidChange(self, key: key) delegate?.valueDidChange(self, key: key)

View File

@ -13,7 +13,9 @@ final class FeedbinAPICaller: NSObject {
private let feedbinBaseURL = URL(string: "https://api.feedbin.com/v2/")! private let feedbinBaseURL = URL(string: "https://api.feedbin.com/v2/")!
private var transport: Transport! private var transport: Transport!
var credentials: Credentials? var credentials: Credentials?
var accountMetadata: AccountMetadata?
init(transport: Transport) { init(transport: Transport) {
super.init() super.init()

View File

@ -21,8 +21,11 @@ final class FeedbinAccountDelegate: AccountDelegate {
} }
} }
var settings: AccountSettings? var accountMetadata: AccountMetadata? {
didSet {
caller.accountMetadata = accountMetadata
}
}
init(transport: Transport) { init(transport: Transport) {
caller = FeedbinAPICaller(transport: transport) caller = FeedbinAPICaller(transport: transport)

View File

@ -14,7 +14,7 @@ final class LocalAccountDelegate: AccountDelegate {
let supportsSubFolders = false let supportsSubFolders = false
let server: String? = nil let server: String? = nil
var credentials: Credentials? var credentials: Credentials?
var settings: AccountSettings? var accountMetadata: AccountMetadata?
private let refresher = LocalAccountRefresher() private let refresher = LocalAccountRefresher()