mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-30 09:18:18 +00:00
Rename AccountMetadata to AccountSettings. Persist to a SQLite database instead of to a plist.
This commit is contained in:
1 parent
b09df86904
commit
2f047374f5
2 files changed
+96
-101
No files matched your search
@@ -1,101 +0,0 @@
|
||||
//
|
||||
// AccountMetadata.swift
|
||||
// Account
|
||||
//
|
||||
// Created by Brent Simmons on 3/3/19.
|
||||
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RSWeb
|
||||
|
||||
protocol AccountMetadataDelegate: AnyObject {
|
||||
@MainActor func valueDidChange(_ accountMetadata: AccountMetadata, key: AccountMetadata.CodingKeys)
|
||||
}
|
||||
|
||||
@MainActor final class AccountMetadata: @MainActor Codable {
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case name
|
||||
case isActive
|
||||
case username
|
||||
case conditionalGetInfo
|
||||
case lastArticleFetchStartTime = "lastArticleFetch"
|
||||
case lastArticleFetchEndTime
|
||||
case endpointURL
|
||||
case externalID
|
||||
case performedApril2020RetentionPolicyChange
|
||||
}
|
||||
|
||||
@MainActor var name: String? {
|
||||
didSet {
|
||||
if name != oldValue {
|
||||
valueDidChange(.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor var isActive: Bool = true {
|
||||
didSet {
|
||||
if isActive != oldValue {
|
||||
valueDidChange(.isActive)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor var username: String? {
|
||||
didSet {
|
||||
if username != oldValue {
|
||||
valueDidChange(.username)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor var conditionalGetInfo = [String: HTTPConditionalGetInfo]() {
|
||||
didSet {
|
||||
if conditionalGetInfo != oldValue {
|
||||
valueDidChange(.conditionalGetInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor var lastArticleFetchStartTime: Date? {
|
||||
didSet {
|
||||
if lastArticleFetchStartTime != oldValue {
|
||||
valueDidChange(.lastArticleFetchStartTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor var lastArticleFetchEndTime: Date? {
|
||||
didSet {
|
||||
if lastArticleFetchEndTime != oldValue {
|
||||
valueDidChange(.lastArticleFetchEndTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor var endpointURL: URL? {
|
||||
didSet {
|
||||
if endpointURL != oldValue {
|
||||
valueDidChange(.endpointURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var performedApril2020RetentionPolicyChange: Bool? // No longer used.
|
||||
|
||||
@MainActor var externalID: String? {
|
||||
didSet {
|
||||
if externalID != oldValue {
|
||||
valueDidChange(.externalID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor weak var delegate: AccountMetadataDelegate?
|
||||
|
||||
@MainActor func valueDidChange(_ key: CodingKeys) {
|
||||
delegate?.valueDidChange(self, key: key)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// AccountSettings.swift
|
||||
// Account
|
||||
//
|
||||
// Created by Brent Simmons on 3/3/19.
|
||||
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import RSWeb
|
||||
|
||||
/// AccountSettings is backed by AccountSettingsDatabase.
|
||||
/// Setting a property here will save it immediately.
|
||||
@MainActor final class AccountSettings {
|
||||
private let accountID: String
|
||||
private let database: AccountSettingsDatabase
|
||||
|
||||
var name: String? {
|
||||
didSet {
|
||||
if name != oldValue {
|
||||
database.setString(name, for: accountID, column: .name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var isActive: Bool = true {
|
||||
didSet {
|
||||
if isActive != oldValue {
|
||||
database.setBool(isActive, for: accountID, column: .isActive)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var username: String? {
|
||||
didSet {
|
||||
if username != oldValue {
|
||||
database.setString(username, for: accountID, column: .username)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func conditionalGetInfo(for endpoint: String) -> HTTPConditionalGetInfo? {
|
||||
database.conditionalGetInfo(for: accountID, endpoint: endpoint)
|
||||
}
|
||||
|
||||
func setConditionalGetInfo(_ info: HTTPConditionalGetInfo?, for endpoint: String) {
|
||||
database.setConditionalGetInfo(info, for: accountID, endpoint: endpoint)
|
||||
}
|
||||
|
||||
var lastArticleFetchStartTime: Date? {
|
||||
didSet {
|
||||
if lastArticleFetchStartTime != oldValue {
|
||||
database.setDate(lastArticleFetchStartTime, for: accountID, column: .lastArticleFetchStartTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var lastArticleFetchEndTime: Date? {
|
||||
didSet {
|
||||
if lastArticleFetchEndTime != oldValue {
|
||||
database.setDate(lastArticleFetchEndTime, for: accountID, column: .lastArticleFetchEndTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var endpointURL: URL? {
|
||||
didSet {
|
||||
if endpointURL != oldValue {
|
||||
database.setString(endpointURL?.absoluteString, for: accountID, column: .endpointURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var externalID: String? {
|
||||
didSet {
|
||||
if externalID != oldValue {
|
||||
database.setString(externalID, for: accountID, column: .externalID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(accountID: String, database: AccountSettingsDatabase) {
|
||||
self.accountID = accountID
|
||||
self.database = database
|
||||
|
||||
if let row = database.row(for: accountID) {
|
||||
self.name = row.name
|
||||
self.isActive = row.isActive
|
||||
self.username = row.username
|
||||
self.lastArticleFetchStartTime = row.lastArticleFetchStartTime
|
||||
self.lastArticleFetchEndTime = row.lastArticleFetchEndTime
|
||||
self.endpointURL = row.endpointURL
|
||||
self.externalID = row.externalID
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user