2017-11-19 22:57:42 +01:00
|
|
|
//
|
|
|
|
// UnreadFeed.swift
|
2018-08-29 07:18:24 +02:00
|
|
|
// NetNewsWire
|
2017-11-19 22:57:42 +01:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 11/19/17.
|
|
|
|
// Copyright © 2017 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
#if os(macOS)
|
2018-02-12 07:10:28 +01:00
|
|
|
import AppKit
|
2019-04-15 22:03:05 +02:00
|
|
|
#else
|
|
|
|
import Foundation
|
|
|
|
#endif
|
2018-02-10 22:00:53 +01:00
|
|
|
import Account
|
2018-07-24 03:29:08 +02:00
|
|
|
import Articles
|
2017-11-19 22:57:42 +01:00
|
|
|
|
|
|
|
// This just shows the global unread count, which appDelegate already has. Easy.
|
|
|
|
|
|
|
|
final class UnreadFeed: PseudoFeed {
|
|
|
|
|
|
|
|
let nameForDisplay = NSLocalizedString("All Unread", comment: "All Unread pseudo-feed title")
|
|
|
|
|
|
|
|
var unreadCount = 0 {
|
|
|
|
didSet {
|
|
|
|
if unreadCount != oldValue {
|
|
|
|
postUnreadCountDidChangeNotification()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 22:03:05 +02:00
|
|
|
#if os(macOS)
|
2018-02-12 07:10:28 +01:00
|
|
|
var pasteboardWriter: NSPasteboardWriting {
|
|
|
|
return SmartFeedPasteboardWriter(smartFeed: self)
|
|
|
|
}
|
2019-04-15 22:03:05 +02:00
|
|
|
#endif
|
2018-02-12 07:10:28 +01:00
|
|
|
|
2017-11-19 22:57:42 +01:00
|
|
|
init() {
|
|
|
|
|
|
|
|
self.unreadCount = appDelegate.unreadCount
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: appDelegate)
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc func unreadCountDidChange(_ note: Notification) {
|
|
|
|
|
|
|
|
assert(note.object is AppDelegate)
|
|
|
|
unreadCount = appDelegate.unreadCount
|
|
|
|
}
|
|
|
|
}
|
2018-02-10 22:00:53 +01:00
|
|
|
|
|
|
|
extension UnreadFeed: ArticleFetcher {
|
|
|
|
|
|
|
|
func fetchArticles() -> Set<Article> {
|
|
|
|
|
|
|
|
return fetchUnreadArticles()
|
|
|
|
}
|
|
|
|
|
|
|
|
func fetchUnreadArticles() -> Set<Article> {
|
|
|
|
|
|
|
|
var articles = Set<Article>()
|
|
|
|
for account in AccountManager.shared.accounts {
|
|
|
|
articles.formUnion(account.fetchUnreadArticles())
|
|
|
|
}
|
|
|
|
return articles
|
|
|
|
}
|
|
|
|
}
|