Rename Account.type to Account.accountType.

This commit is contained in:
Brent Simmons 2024-06-09 22:53:19 -07:00
parent 96fefbc800
commit c1f6026495
16 changed files with 35 additions and 32 deletions

@ -17,7 +17,7 @@ import ParserObjC
import Database import Database
import ArticlesDatabase import ArticlesDatabase
import Web import Web
import os.log import os
import Secrets import Secrets
import Core import Core
import CommonErrors import CommonErrors
@ -95,7 +95,7 @@ public enum FetchType {
return defaultName return defaultName
}() }()
var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "account") private let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Account")
public var isDeleted = false public var isDeleted = false
@ -107,7 +107,7 @@ public enum FetchType {
return self return self
} }
public let accountID: String public let accountID: String
public let type: AccountType public let accountType: AccountType
public var nameForDisplay: String { public var nameForDisplay: String {
guard let name = name, !name.isEmpty else { guard let name = name, !name.isEmpty else {
return defaultName return defaultName
@ -295,7 +295,7 @@ public enum FetchType {
self.delegate.accountMetadata = metadata self.delegate.accountMetadata = metadata
self.accountID = accountID self.accountID = accountID
self.type = type self.accountType = type
self.dataFolder = dataFolder self.dataFolder = dataFolder
let databasePath = (dataFolder as NSString).appendingPathComponent("DB.sqlite3") let databasePath = (dataFolder as NSString).appendingPathComponent("DB.sqlite3")
@ -751,6 +751,9 @@ public enum FetchType {
public func structureDidChange() { public func structureDidChange() {
// Feeds were added or deleted. Or folders added or deleted. // Feeds were added or deleted. Or folders added or deleted.
// Or feeds inside folders were added or deleted. // Or feeds inside folders were added or deleted.
logger.info("structureDidChange in account \(self.accountID)")
Task { @MainActor in Task { @MainActor in
opmlFile.markAsDirty() opmlFile.markAsDirty()
flattenedFeedsNeedUpdate = true flattenedFeedsNeedUpdate = true
@ -762,7 +765,7 @@ public enum FetchType {
func update(feed: Feed, with parsedFeed: ParsedFeed) async throws -> ArticleChanges { func update(feed: Feed, with parsedFeed: ParsedFeed) async throws -> ArticleChanges {
precondition(Thread.isMainThread) precondition(Thread.isMainThread)
precondition(type == .onMyMac || type == .cloudKit) precondition(accountType == .onMyMac || accountType == .cloudKit)
feed.takeSettings(from: parsedFeed) feed.takeSettings(from: parsedFeed)
@ -777,7 +780,7 @@ public enum FetchType {
func update(feedID: String, with parsedItems: Set<ParsedItem>, deleteOlder: Bool = true) async throws -> ArticleChanges { func update(feedID: String, with parsedItems: Set<ParsedItem>, deleteOlder: Bool = true) async throws -> ArticleChanges {
precondition(Thread.isMainThread) precondition(Thread.isMainThread)
precondition(type == .onMyMac || type == .cloudKit) precondition(accountType == .onMyMac || accountType == .cloudKit)
let articleChanges = try await database.update(parsedItems: parsedItems, feedID: feedID, deleteOlder: deleteOlder) let articleChanges = try await database.update(parsedItems: parsedItems, feedID: feedID, deleteOlder: deleteOlder)
self.sendNotificationAbout(articleChanges) self.sendNotificationAbout(articleChanges)
@ -787,7 +790,7 @@ public enum FetchType {
func update(feedIDsAndItems: [String: Set<ParsedItem>], defaultRead: Bool) async throws { func update(feedIDsAndItems: [String: Set<ParsedItem>], defaultRead: Bool) async throws {
precondition(Thread.isMainThread) precondition(Thread.isMainThread)
precondition(type != .onMyMac && type != .cloudKit) precondition(accountType != .onMyMac && accountType != .cloudKit)
guard !feedIDsAndItems.isEmpty else { guard !feedIDsAndItems.isEmpty else {
return return

@ -176,7 +176,7 @@ import Secrets
return false return false
} }
for account in accounts { for account in accounts {
if account.type == type && username == account.username { if account.accountType == type && username == account.username {
return true return true
} }
} }
@ -414,7 +414,7 @@ private extension AccountManager {
} }
func duplicateServiceAccount(_ account: Account) -> Bool { func duplicateServiceAccount(_ account: Account) -> Bool {
return duplicateServiceAccount(type: account.type, username: account.username) return duplicateServiceAccount(type: account.accountType, username: account.username)
} }
func sortByName(_ accounts: [Account]) -> [Account] { func sortByName(_ accounts: [Account]) -> [Account] {

@ -24,7 +24,7 @@ import Core
continue continue
} }
if restrictToSpecialAccounts && !(account.type == .onMyMac || account.type == .cloudKit) { if restrictToSpecialAccounts && !(account.accountType == .onMyMac || account.accountType == .cloudKit) {
continue continue
} }

@ -207,7 +207,7 @@ extension Feed: PasteboardWriterOwner {
private extension FeedPasteboardWriter { private extension FeedPasteboardWriter {
var pasteboardFeed: PasteboardFeed { var pasteboardFeed: PasteboardFeed {
return PasteboardFeed(url: feed.url, feedID: feed.feedID, homePageURL: feed.homePageURL, name: feed.name, editedName: feed.editedName, accountID: feed.account?.accountID, accountType: feed.account?.type) return PasteboardFeed(url: feed.url, feedID: feed.feedID, homePageURL: feed.homePageURL, name: feed.name, editedName: feed.editedName, accountID: feed.account?.accountID, accountType: feed.account?.accountType)
} }
var exportDictionary: PasteboardFeedDictionary { var exportDictionary: PasteboardFeedDictionary {

@ -32,7 +32,7 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
guard let account = account else { guard let account = account else {
return true return true
} }
switch account.type { switch account.accountType {
case .onMyMac, .cloudKit, .feedly: case .onMyMac, .cloudKit, .feedly:
return true return true
default: default:
@ -66,7 +66,7 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
guard let account else { return } guard let account else { return }
switch account.type { switch account.accountType {
case .feedbin: case .feedbin:
let accountsFeedbinWindowController = AccountsFeedbinWindowController() let accountsFeedbinWindowController = AccountsFeedbinWindowController()
@ -76,7 +76,7 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
case .inoreader, .bazQux, .theOldReader, .freshRSS: case .inoreader, .bazQux, .theOldReader, .freshRSS:
let accountsReaderAPIWindowController = AccountsReaderAPIWindowController() let accountsReaderAPIWindowController = AccountsReaderAPIWindowController()
accountsReaderAPIWindowController.accountType = account.type accountsReaderAPIWindowController.accountType = account.accountType
accountsReaderAPIWindowController.account = account accountsReaderAPIWindowController.account = account
accountsReaderAPIWindowController.runSheetOnWindow(self.view.window!) accountsReaderAPIWindowController.runSheetOnWindow(self.view.window!)
accountsWindowController = accountsReaderAPIWindowController accountsWindowController = accountsReaderAPIWindowController

@ -118,7 +118,7 @@ extension AccountsPreferencesViewController: NSTableViewDelegate {
cell.textField?.stringValue = account.nameForDisplay cell.textField?.stringValue = account.nameForDisplay
cell.imageView?.image = account.smallIcon?.image cell.imageView?.image = account.smallIcon?.image
if account.type == .feedbin { if account.accountType == .feedbin {
cell.isImageTemplateCapable = false cell.isImageTemplateCapable = false
} }

@ -22,7 +22,7 @@ struct AddAccountHelpView: View {
ForEach(accountTypes, id: \.self) { accountType in ForEach(accountTypes, id: \.self) { accountType in
if !(AppDefaults.shared.isDeveloperBuild && accountType.isDeveloperRestricted) { if !(AppDefaults.shared.isDeveloperBuild && accountType.isDeveloperRestricted) {
Button(action: { Button(action: {
if accountType == .cloudKit && AccountManager.shared.accounts.contains(where: { $0.type == .cloudKit }) { if accountType == .cloudKit && AccountManager.shared.accounts.contains(where: { $0.accountType == .cloudKit }) {
iCloudUnavailableError = true iCloudUnavailableError = true
} else { } else {
delegate?.presentSheetForAccount(accountType) delegate?.presentSheetForAccount(accountType)

@ -260,7 +260,7 @@ struct AddAccountsView: View {
} }
@MainActor private func isCloudInUse() -> Bool { @MainActor private func isCloudInUse() -> Bool {
AccountManager.shared.accounts.contains(where: { $0.type == .cloudKit }) AccountManager.shared.accounts.contains(where: { $0.accountType == .cloudKit })
} }
private func chunkedWebAccounts() -> [[AccountType]] { private func chunkedWebAccounts() -> [[AccountType]] {

@ -156,7 +156,7 @@ import Core
@objc(accountType) @objc(accountType)
var accountType:OSType { var accountType:OSType {
var osType:String = "" var osType:String = ""
switch self.account.type { switch self.account.accountType {
case .onMyMac: case .onMyMac:
osType = "Locl" osType = "Locl"
case .cloudKit: case .cloudKit:

@ -18,7 +18,7 @@ protocol SmallIconProvider {
extension Account: SmallIconProvider { extension Account: SmallIconProvider {
var smallIcon: IconImage? { var smallIcon: IconImage? {
if let image = AppAssets.image(for: type) { if let image = AppAssets.image(for: accountType) {
return IconImage(image) return IconImage(image)
} }
return nil return nil

@ -58,7 +58,7 @@ struct ExtensionContainers: Codable {
init(account: Account) { init(account: Account) {
self.name = account.nameForDisplay self.name = account.nameForDisplay
self.accountID = account.accountID self.accountID = account.accountID
self.type = account.type self.type = account.accountType
self.disallowFeedInRootFolder = account.behaviors.contains(.disallowFeedInRootFolder) self.disallowFeedInRootFolder = account.behaviors.contains(.disallowFeedInRootFolder)
self.containerID = account.containerID self.containerID = account.containerID
self.folders = account.sortedFolders?.map { ExtensionFolder(folder: $0) } ?? [ExtensionFolder]() self.folders = account.sortedFolders?.map { ExtensionFolder(folder: $0) } ?? [ExtensionFolder]()

@ -30,7 +30,7 @@ final class AddFeedFolderViewController: UITableViewController {
if addFeedType == .web { if addFeedType == .web {
sortedActiveAccounts = AccountManager.shared.sortedActiveAccounts sortedActiveAccounts = AccountManager.shared.sortedActiveAccounts
} else { } else {
sortedActiveAccounts = AccountManager.shared.sortedActiveAccounts.filter { $0.type == .onMyMac || $0.type == .cloudKit } sortedActiveAccounts = AccountManager.shared.sortedActiveAccounts.filter { $0.accountType == .onMyMac || $0.accountType == .cloudKit }
} }
for account in sortedActiveAccounts { for account in sortedActiveAccounts {

@ -32,7 +32,7 @@ class AccountInspectorViewController: UITableViewController {
navigationItem.title = account.nameForDisplay navigationItem.title = account.nameForDisplay
if account.type != .onMyMac { if account.accountType != .onMyMac {
deleteAccountButton.setTitle(NSLocalizedString("Remove Account", comment: "Remove Account"), for: .normal) deleteAccountButton.setTitle(NSLocalizedString("Remove Account", comment: "Remove Account"), for: .normal)
} }
@ -56,7 +56,7 @@ class AccountInspectorViewController: UITableViewController {
@IBAction func credentials(_ sender: Any) { @IBAction func credentials(_ sender: Any) {
guard let account = account else { return } guard let account = account else { return }
switch account.type { switch account.accountType {
case .feedbin: case .feedbin:
let navController = UIStoryboard.account.instantiateViewController(withIdentifier: "FeedbinAccountNavigationViewController") as! UINavigationController let navController = UIStoryboard.account.instantiateViewController(withIdentifier: "FeedbinAccountNavigationViewController") as! UINavigationController
let addViewController = navController.topViewController as! FeedbinAccountViewController let addViewController = navController.topViewController as! FeedbinAccountViewController
@ -72,7 +72,7 @@ class AccountInspectorViewController: UITableViewController {
case .inoreader, .bazQux, .theOldReader, .freshRSS: case .inoreader, .bazQux, .theOldReader, .freshRSS:
let navController = UIStoryboard.account.instantiateViewController(withIdentifier: "ReaderAPIAccountNavigationViewController") as! UINavigationController let navController = UIStoryboard.account.instantiateViewController(withIdentifier: "ReaderAPIAccountNavigationViewController") as! UINavigationController
let addViewController = navController.topViewController as! ReaderAPIAccountViewController let addViewController = navController.topViewController as! ReaderAPIAccountViewController
addViewController.accountType = account.type addViewController.accountType = account.accountType
addViewController.account = account addViewController.account = account
navController.modalPresentationStyle = .currentContext navController.modalPresentationStyle = .currentContext
present(navController, animated: true) present(navController, animated: true)
@ -88,7 +88,7 @@ class AccountInspectorViewController: UITableViewController {
let title = NSLocalizedString("Remove Account", comment: "Remove Account") let title = NSLocalizedString("Remove Account", comment: "Remove Account")
let message: String = { let message: String = {
switch account.type { switch account.accountType {
case .feedly: case .feedly:
return NSLocalizedString("Are you sure you want to remove this account? NetNewsWire will no longer be able to access articles and feeds unless the account is added again.", comment: "Log Out and Remove Account") return NSLocalizedString("Are you sure you want to remove this account? NetNewsWire will no longer be able to access articles and feeds unless the account is added again.", comment: "Log Out and Remove Account")
default: default:
@ -125,7 +125,7 @@ extension AccountInspectorViewController {
guard let account = account else { guard let account = account else {
return true return true
} }
switch account.type { switch account.accountType {
case .onMyMac, .cloudKit, .feedly: case .onMyMac, .cloudKit, .feedly:
return true return true
default: default:
@ -154,7 +154,7 @@ extension AccountInspectorViewController {
if section == 0 { if section == 0 {
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! ImageHeaderView let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "SectionHeader") as! ImageHeaderView
headerView.imageView.image = AppAssets.image(for: account.type) headerView.imageView.image = AppAssets.image(for: account.accountType)
return headerView return headerView
} else { } else {
return super.tableView(tableView, viewForHeaderInSection: section) return super.tableView(tableView, viewForHeaderInSection: section)

@ -137,7 +137,7 @@ final class AddAccountViewController: UITableViewController, AddAccountDismissDe
case AddAccountSections.icloud.rawValue: case AddAccountSections.icloud.rawValue:
cell.comboNameLabel?.text = AddAccountSections.icloud.sectionContent[indexPath.row].localizedAccountName() cell.comboNameLabel?.text = AddAccountSections.icloud.sectionContent[indexPath.row].localizedAccountName()
cell.comboImage?.image = AppAssets.image(for: AddAccountSections.icloud.sectionContent[indexPath.row]) cell.comboImage?.image = AppAssets.image(for: AddAccountSections.icloud.sectionContent[indexPath.row])
if AppDefaults.shared.isDeveloperBuild || AccountManager.shared.accounts.contains(where: { $0.type == .cloudKit }) { if AppDefaults.shared.isDeveloperBuild || AccountManager.shared.accounts.contains(where: { $0.accountType == .cloudKit }) {
cell.isUserInteractionEnabled = false cell.isUserInteractionEnabled = false
cell.comboNameLabel?.isEnabled = false cell.comboNameLabel?.isEnabled = false
} }

@ -146,7 +146,7 @@ final class SettingsViewController: UITableViewController {
let acctCell = tableView.dequeueReusableCell(withIdentifier: "SettingsComboTableViewCell", for: indexPath) as! SettingsComboTableViewCell let acctCell = tableView.dequeueReusableCell(withIdentifier: "SettingsComboTableViewCell", for: indexPath) as! SettingsComboTableViewCell
acctCell.applyThemeProperties() acctCell.applyThemeProperties()
let account = sortedAccounts[indexPath.row] let account = sortedAccounts[indexPath.row]
acctCell.comboImage?.image = AppAssets.image(for: account.type) acctCell.comboImage?.image = AppAssets.image(for: account.accountType)
acctCell.comboNameLabel?.text = account.nameForDisplay acctCell.comboNameLabel?.text = account.nameForDisplay
cell = acctCell cell = acctCell
} }

@ -60,7 +60,7 @@ private extension UIViewController {
let title = NSLocalizedString("Account Error", comment: "Account Error") let title = NSLocalizedString("Account Error", comment: "Account Error")
let alertController = UIAlertController(title: title, message: error.localizedDescription, preferredStyle: .alert) let alertController = UIAlertController(title: title, message: error.localizedDescription, preferredStyle: .alert)
if error.account?.type == .feedbin { if error.account?.accountType == .feedbin {
let credentialsTitle = NSLocalizedString("Update Credentials", comment: "Update Credentials") let credentialsTitle = NSLocalizedString("Update Credentials", comment: "Update Credentials")
let credentialsAction = UIAlertAction(title: credentialsTitle, style: .default) { [weak self] _ in let credentialsAction = UIAlertAction(title: credentialsTitle, style: .default) { [weak self] _ in