Update code formatting in Account.

This commit is contained in:
Brent Simmons 2019-07-08 23:06:40 -07:00
parent 1e998543a5
commit 055e0f09ad
2 changed files with 3 additions and 40 deletions

View File

@ -1,6 +1,6 @@
// //
// Account.swift // Account.swift
// DataModel // NetNewsWire
// //
// Created by Brent Simmons on 7/1/17. // Created by Brent Simmons on 7/1/17.
// Copyright © 2017 Ranchero Software, LLC. All rights reserved. // Copyright © 2017 Ranchero Software, LLC. All rights reserved.
@ -211,7 +211,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
init?(dataFolder: String, type: AccountType, accountID: String, transport: Transport? = nil) { init?(dataFolder: String, type: AccountType, accountID: String, transport: Transport? = nil) {
switch type { switch type {
case .onMyMac: case .onMyMac:
self.delegate = LocalAccountDelegate() self.delegate = LocalAccountDelegate()
@ -248,12 +247,10 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
NotificationCenter.default.addObserver(self, selector: #selector(downloadProgressDidChange(_:)), name: .DownloadProgressDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(downloadProgressDidChange(_:)), name: .DownloadProgressDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(childrenDidChange(_:)), name: .ChildrenDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(childrenDidChange(_:)), name: .ChildrenDidChange, object: nil)
pullObjectsFromDisk() pullObjectsFromDisk()
DispatchQueue.main.async { DispatchQueue.main.async {
@ -262,7 +259,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
self.delegate.accountDidInitialize(self) self.delegate.accountDidInitialize(self)
startingUp = false startingUp = false
} }
// MARK: - API // MARK: - API
@ -282,7 +278,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
try CredentialsManager.storeCredentials(credentials, server: server) try CredentialsManager.storeCredentials(credentials, server: server)
delegate.credentials = credentials delegate.credentials = credentials
} }
public func retrieveBasicCredentials() throws -> Credentials? { public func retrieveBasicCredentials() throws -> Credentials? {
@ -324,7 +319,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
public func importOPML(_ opmlFile: URL, completion: @escaping (Result<Void, Error>) -> Void) { public func importOPML(_ opmlFile: URL, completion: @escaping (Result<Void, Error>) -> Void) {
guard !delegate.opmlImportInProgress else { guard !delegate.opmlImportInProgress else {
completion(.failure(AccountError.opmlImportInProgress)) completion(.failure(AccountError.opmlImportInProgress))
return return
@ -350,7 +344,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
@discardableResult @discardableResult
public func ensureFolder(with name: String) -> Folder? { public func ensureFolder(with name: String) -> Folder? {
// TODO: support subfolders, maybe, some day // TODO: support subfolders, maybe, some day
if name.isEmpty { if name.isEmpty {
@ -370,7 +363,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
public func ensureFolder(withFolderNames folderNames: [String]) -> Folder? { public func ensureFolder(withFolderNames folderNames: [String]) -> Folder? {
// TODO: support subfolders, maybe, some day. // TODO: support subfolders, maybe, some day.
// Since we dont, just take the last name and make sure theres a Folder. // Since we dont, just take the last name and make sure theres a Folder.
@ -401,14 +393,12 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
func createFeed(with name: String?, url: String, feedID: String, homePageURL: String?) -> Feed { func createFeed(with name: String?, url: String, feedID: String, homePageURL: String?) -> Feed {
let metadata = feedMetadata(feedURL: url, feedID: feedID) let metadata = feedMetadata(feedURL: url, feedID: feedID)
let feed = Feed(account: self, url: url, metadata: metadata) let feed = Feed(account: self, url: url, metadata: metadata)
feed.name = name feed.name = name
feed.homePageURL = homePageURL feed.homePageURL = homePageURL
return feed return feed
} }
public func removeFeed(_ feed: Feed, from container: Container?, completion: @escaping (Result<Void, Error>) -> Void) { public func removeFeed(_ feed: Feed, from container: Container?, completion: @escaping (Result<Void, Error>) -> Void) {
@ -454,7 +444,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
func loadOPML(_ opmlDocument: RSOPMLDocument) { func loadOPML(_ opmlDocument: RSOPMLDocument) {
guard let children = opmlDocument.children else { guard let children = opmlDocument.children else {
return return
} }
@ -468,13 +457,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
public func updateUnreadCounts(for feeds: Set<Feed>) { public func updateUnreadCounts(for feeds: Set<Feed>) {
if feeds.isEmpty { if feeds.isEmpty {
return return
} }
database.fetchUnreadCounts(for: feeds.feedIDs()) { (unreadCountDictionary) in database.fetchUnreadCounts(for: feeds.feedIDs()) { (unreadCountDictionary) in
for feed in feeds { for feed in feeds {
if let unreadCount = unreadCountDictionary[feed.feedID] { if let unreadCount = unreadCountDictionary[feed.feedID] {
feed.unreadCount = unreadCount feed.unreadCount = unreadCount
@ -521,15 +508,12 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
} }
public func fetchUnreadCountForToday(_ callback: @escaping (Int) -> Void) { public func fetchUnreadCountForToday(_ callback: @escaping (Int) -> Void) {
let startOfToday = NSCalendar.startOfToday() let startOfToday = NSCalendar.startOfToday()
database.fetchUnreadCount(for: flattenedFeeds().feedIDs(), since: startOfToday, callback: callback) database.fetchUnreadCount(for: flattenedFeeds().feedIDs(), since: startOfToday, callback: callback)
} }
public func fetchUnreadCountForStarredArticles(_ callback: @escaping (Int) -> Void) { public func fetchUnreadCountForStarredArticles(_ callback: @escaping (Int) -> Void) {
database.fetchStarredAndUnreadCount(for: flattenedFeeds().feedIDs(), callback: callback) database.fetchStarredAndUnreadCount(for: flattenedFeeds().feedIDs(), callback: callback)
} }
@ -595,9 +579,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
func update(_ feed: Feed, parsedItems: Set<ParsedItem>, defaultRead: Bool = false, _ completion: @escaping (() -> Void)) { func update(_ feed: Feed, parsedItems: Set<ParsedItem>, defaultRead: Bool = false, _ completion: @escaping (() -> Void)) {
database.update(feedID: feed.feedID, parsedItems: parsedItems, defaultRead: defaultRead) { (newArticles, updatedArticles) in database.update(feedID: feed.feedID, parsedItems: parsedItems, defaultRead: defaultRead) { (newArticles, updatedArticles) in
var userInfo = [String: Any]() var userInfo = [String: Any]()
if let newArticles = newArticles, !newArticles.isEmpty { if let newArticles = newArticles, !newArticles.isEmpty {
self.updateUnreadCounts(for: Set([feed])) self.updateUnreadCounts(for: Set([feed]))
@ -612,7 +594,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
NotificationCenter.default.post(name: .AccountDidDownloadArticles, object: self, userInfo: userInfo) NotificationCenter.default.post(name: .AccountDidDownloadArticles, object: self, userInfo: userInfo)
} }
} }
@discardableResult @discardableResult
@ -627,7 +608,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
noteStatusesForArticlesDidChange(updatedArticles) noteStatusesForArticlesDidChange(updatedArticles)
return updatedArticles return updatedArticles
} }
func ensureStatuses(_ articleIDs: Set<String>, _ statusKey: ArticleStatus.Key, _ flag: Bool) { func ensureStatuses(_ articleIDs: Set<String>, _ statusKey: ArticleStatus.Key, _ flag: Bool) {
@ -673,7 +653,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
// MARK: - Debug // MARK: - Debug
public func debugDropConditionalGetInfo() { public func debugDropConditionalGetInfo() {
#if DEBUG #if DEBUG
flattenedFeeds().forEach{ $0.debugDropConditionalGetInfo() } flattenedFeeds().forEach{ $0.debugDropConditionalGetInfo() }
#endif #endif
@ -692,7 +671,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
// MARK: - Notifications // MARK: - Notifications
@objc func downloadProgressDidChange(_ note: Notification) { @objc func downloadProgressDidChange(_ note: Notification) {
guard let noteObject = note.object as? DownloadProgress, noteObject === refreshProgress else { guard let noteObject = note.object as? DownloadProgress, noteObject === refreshProgress else {
return return
} }
@ -708,14 +686,12 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
@objc func batchUpdateDidPerform(_ note: Notification) { @objc func batchUpdateDidPerform(_ note: Notification) {
flattenedFeedsNeedUpdate = true flattenedFeedsNeedUpdate = true
rebuildFeedDictionaries() rebuildFeedDictionaries()
updateUnreadCount() updateUnreadCount()
} }
@objc func childrenDidChange(_ note: Notification) { @objc func childrenDidChange(_ note: Notification) {
guard let object = note.object else { guard let object = note.object else {
return return
} }
@ -729,14 +705,12 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
} }
@objc func displayNameDidChange(_ note: Notification) { @objc func displayNameDidChange(_ note: Notification) {
if let folder = note.object as? Folder, folder.account === self { if let folder = note.object as? Folder, folder.account === self {
structureDidChange() structureDidChange()
} }
} }
@objc func saveToDiskIfNeeded() { @objc func saveToDiskIfNeeded() {
if dirty && !isDeleted { if dirty && !isDeleted {
saveToDisk() saveToDisk()
} }
@ -763,7 +737,6 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
// MARK: - Equatable // MARK: - Equatable
public class func ==(lhs: Account, rhs: Account) -> Bool { public class func ==(lhs: Account, rhs: Account) -> Bool {
return lhs === rhs return lhs === rhs
} }
} }
@ -900,7 +873,6 @@ private extension Account {
} }
func validateUnreadCount(_ feed: Feed, _ articles: Set<Article>) { func validateUnreadCount(_ feed: Feed, _ articles: Set<Article>) {
// articles must contain all the unread articles for the feed. // articles must contain all the unread articles for the feed.
// The unread number should match the feeds unread count. // The unread number should match the feeds unread count.
@ -985,11 +957,9 @@ private extension Account {
BatchUpdate.shared.perform { BatchUpdate.shared.perform {
loadOPMLItems(children, parentFolder: nil) loadOPMLItems(children, parentFolder: nil)
} }
} }
func saveToDisk() { func saveToDisk() {
dirty = false dirty = false
let opmlDocumentString = opmlDocument() let opmlDocumentString = opmlDocument()
@ -1091,7 +1061,6 @@ private extension Account {
} }
func loadOPMLItems(_ items: [RSOPMLItem], parentFolder: Folder?) { func loadOPMLItems(_ items: [RSOPMLItem], parentFolder: Folder?) {
var feedsToAdd = Set<Feed>() var feedsToAdd = Set<Feed>()
items.forEach { (item) in items.forEach { (item) in
@ -1141,7 +1110,6 @@ private extension Account {
} }
func noteStatusesForArticlesDidChange(_ articles: Set<Article>) { func noteStatusesForArticlesDidChange(_ articles: Set<Article>) {
let feeds = Set(articles.compactMap { $0.feed }) let feeds = Set(articles.compactMap { $0.feed })
let statuses = Set(articles.map { $0.status }) let statuses = Set(articles.map { $0.status })
@ -1153,10 +1121,9 @@ private extension Account {
} }
func fetchAllUnreadCounts() { func fetchAllUnreadCounts() {
fetchingAllUnreadCounts = true fetchingAllUnreadCounts = true
database.fetchAllNonZeroUnreadCounts { (unreadCountDictionary) in
database.fetchAllNonZeroUnreadCounts { (unreadCountDictionary) in
if unreadCountDictionary.isEmpty { if unreadCountDictionary.isEmpty {
self.fetchingAllUnreadCounts = false self.fetchingAllUnreadCounts = false
self.updateUnreadCount() self.updateUnreadCount()
@ -1165,7 +1132,6 @@ private extension Account {
} }
self.flattenedFeeds().forEach{ (feed) in self.flattenedFeeds().forEach{ (feed) in
// When the unread count is zero, it wont appear in unreadCountDictionary. // When the unread count is zero, it wont appear in unreadCountDictionary.
if let unreadCount = unreadCountDictionary[feed.feedID] { if let unreadCount = unreadCountDictionary[feed.feedID] {
@ -1187,10 +1153,8 @@ private extension Account {
extension Account { extension Account {
public func existingFeed(with feedID: String) -> Feed? { public func existingFeed(with feedID: String) -> Feed? {
return idToFeedDictionary[feedID] return idToFeedDictionary[feedID]
} }
} }
// MARK: - OPMLRepresentable // MARK: - OPMLRepresentable
@ -1198,7 +1162,6 @@ extension Account {
extension Account: OPMLRepresentable { extension Account: OPMLRepresentable {
public func OPMLString(indentLevel: Int) -> String { public func OPMLString(indentLevel: Int) -> String {
var s = "" var s = ""
for feed in topLevelFeeds { for feed in topLevelFeeds {
s += feed.OPMLString(indentLevel: indentLevel + 1) s += feed.OPMLString(indentLevel: indentLevel + 1)

View File

@ -1,6 +1,6 @@
// //
// AccountDelegate.swift // AccountDelegate.swift
// Account // NetNewsWire
// //
// Created by Brent Simmons on 9/16/17. // Created by Brent Simmons on 9/16/17.
// Copyright © 2017 Ranchero Software, LLC. All rights reserved. // Copyright © 2017 Ranchero Software, LLC. All rights reserved.