Make whitespace formatting tweaks.
This commit is contained in:
parent
efe8a4ab15
commit
d509477f2f
|
@ -12,7 +12,6 @@ import Articles
|
||||||
import Account
|
import Account
|
||||||
|
|
||||||
protocol SmartFeedDelegate: DisplayNameProvider, ArticleFetcher {
|
protocol SmartFeedDelegate: DisplayNameProvider, ArticleFetcher {
|
||||||
|
|
||||||
func fetchUnreadCount(for: Account, callback: @escaping (Int) -> Void)
|
func fetchUnreadCount(for: Account, callback: @escaping (Int) -> Void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,21 +37,18 @@ final class SmartFeed: PseudoFeed {
|
||||||
private var unreadCounts = [Account: Int]()
|
private var unreadCounts = [Account: Int]()
|
||||||
|
|
||||||
init(delegate: SmartFeedDelegate) {
|
init(delegate: SmartFeedDelegate) {
|
||||||
|
|
||||||
self.delegate = delegate
|
self.delegate = delegate
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||||
queueFetchUnreadCounts() // Fetch unread count at startup
|
queueFetchUnreadCounts() // Fetch unread count at startup
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func unreadCountDidChange(_ note: Notification) {
|
@objc func unreadCountDidChange(_ note: Notification) {
|
||||||
|
|
||||||
if note.object is Account {
|
if note.object is Account {
|
||||||
queueFetchUnreadCounts()
|
queueFetchUnreadCounts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func fetchUnreadCounts() {
|
@objc func fetchUnreadCounts() {
|
||||||
|
|
||||||
AccountManager.shared.accounts.forEach { self.fetchUnreadCount(for: $0) }
|
AccountManager.shared.accounts.forEach { self.fetchUnreadCount(for: $0) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,12 +56,10 @@ final class SmartFeed: PseudoFeed {
|
||||||
extension SmartFeed: ArticleFetcher {
|
extension SmartFeed: ArticleFetcher {
|
||||||
|
|
||||||
func fetchArticles() -> Set<Article> {
|
func fetchArticles() -> Set<Article> {
|
||||||
|
|
||||||
return delegate.fetchArticles()
|
return delegate.fetchArticles()
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchUnreadArticles() -> Set<Article> {
|
func fetchUnreadArticles() -> Set<Article> {
|
||||||
|
|
||||||
return delegate.fetchUnreadArticles()
|
return delegate.fetchUnreadArticles()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,12 +67,10 @@ extension SmartFeed: ArticleFetcher {
|
||||||
private extension SmartFeed {
|
private extension SmartFeed {
|
||||||
|
|
||||||
func queueFetchUnreadCounts() {
|
func queueFetchUnreadCounts() {
|
||||||
|
|
||||||
CoalescingQueue.standard.add(self, #selector(fetchUnreadCounts))
|
CoalescingQueue.standard.add(self, #selector(fetchUnreadCounts))
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchUnreadCount(for account: Account) {
|
func fetchUnreadCount(for account: Account) {
|
||||||
|
|
||||||
delegate.fetchUnreadCount(for: account) { (accountUnreadCount) in
|
delegate.fetchUnreadCount(for: account) { (accountUnreadCount) in
|
||||||
self.unreadCounts[account] = accountUnreadCount
|
self.unreadCounts[account] = accountUnreadCount
|
||||||
self.updateUnreadCount()
|
self.updateUnreadCount()
|
||||||
|
@ -86,7 +78,6 @@ private extension SmartFeed {
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateUnreadCount() {
|
func updateUnreadCount() {
|
||||||
|
|
||||||
unreadCount = AccountManager.shared.accounts.reduce(0) { (result, account) -> Int in
|
unreadCount = AccountManager.shared.accounts.reduce(0) { (result, account) -> Int in
|
||||||
if let oneUnreadCount = unreadCounts[account] {
|
if let oneUnreadCount = unreadCounts[account] {
|
||||||
return result + oneUnreadCount
|
return result + oneUnreadCount
|
||||||
|
|
Loading…
Reference in New Issue