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
|
2019-09-18 03:26:49 +02:00
|
|
|
import RSCore
|
2018-02-10 22:00:53 +01:00
|
|
|
import Account
|
2018-07-24 03:29:08 +02:00
|
|
|
import Articles
|
2019-12-17 07:45:59 +01:00
|
|
|
import ArticlesDatabase
|
2017-11-19 22:57:42 +01:00
|
|
|
|
|
|
|
// This just shows the global unread count, which appDelegate already has. Easy.
|
|
|
|
|
|
|
|
final class UnreadFeed: PseudoFeed {
|
2021-10-21 02:03:02 +02:00
|
|
|
|
|
|
|
var account: Account? = nil
|
2017-11-19 22:57:42 +01:00
|
|
|
|
2019-11-22 16:40:39 +01:00
|
|
|
public var defaultReadFilterType: ReadFilterType {
|
2019-11-22 16:32:27 +01:00
|
|
|
return .alwaysRead
|
2019-11-22 01:22:43 +01:00
|
|
|
}
|
|
|
|
|
2019-11-15 13:19:14 +01:00
|
|
|
var feedID: FeedIdentifier? {
|
|
|
|
return FeedIdentifier.smartFeed(String(describing: UnreadFeed.self))
|
|
|
|
}
|
|
|
|
|
2017-11-19 22:57:42 +01:00
|
|
|
let nameForDisplay = NSLocalizedString("All Unread", comment: "All Unread pseudo-feed title")
|
2021-03-24 11:43:07 +01:00
|
|
|
let fetchType = FetchType.unread(nil)
|
2019-07-06 05:06:31 +02:00
|
|
|
|
2017-11-19 22:57:42 +01:00
|
|
|
var unreadCount = 0 {
|
|
|
|
didSet {
|
|
|
|
if unreadCount != oldValue {
|
|
|
|
postUnreadCountDidChangeNotification()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-06 23:01:43 +01:00
|
|
|
var smallIcon: IconImage? {
|
|
|
|
return AppAssets.unreadFeedImage
|
|
|
|
}
|
2019-09-18 03:26:49 +02:00
|
|
|
|
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 {
|
2019-11-14 22:06:32 +01:00
|
|
|
|
2019-12-17 07:45:59 +01:00
|
|
|
func fetchArticles() throws -> Set<Article> {
|
|
|
|
return try fetchUnreadArticles()
|
2018-02-10 22:00:53 +01:00
|
|
|
}
|
|
|
|
|
2019-12-17 07:45:59 +01:00
|
|
|
func fetchArticlesAsync(_ completion: @escaping ArticleSetResultBlock) {
|
2019-12-15 02:01:34 +01:00
|
|
|
fetchUnreadArticlesAsync(completion)
|
2019-07-06 05:06:31 +02:00
|
|
|
}
|
|
|
|
|
2019-12-17 07:45:59 +01:00
|
|
|
func fetchUnreadArticles() throws -> Set<Article> {
|
|
|
|
return try AccountManager.shared.fetchArticles(fetchType)
|
2019-07-06 05:06:31 +02:00
|
|
|
}
|
2018-02-10 22:00:53 +01:00
|
|
|
|
2019-12-17 07:45:59 +01:00
|
|
|
func fetchUnreadArticlesAsync(_ completion: @escaping ArticleSetResultBlock) {
|
2019-12-15 02:01:34 +01:00
|
|
|
AccountManager.shared.fetchArticlesAsync(fetchType, completion)
|
2018-02-10 22:00:53 +01:00
|
|
|
}
|
|
|
|
}
|