NetNewsWire/Shared/SmartFeeds/UnreadFeed.swift

79 lines
1.7 KiB
Swift
Raw Normal View History

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.
//
#if os(macOS)
import AppKit
#else
import Foundation
#endif
import Account
import Articles
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 {
var account: Account? = nil
2017-11-19 22:57:42 +01:00
var defaultReadFilterType: ReadFilterType {
return .alwaysRead
2019-11-22 01:22:43 +01:00
}
2024-02-26 06:34:22 +01:00
var sidebarItemID: SidebarItemIdentifier? {
return SidebarItemIdentifier.smartFeed(String(describing: UnreadFeed.self))
2019-11-15 13:19:14 +01:00
}
2017-11-19 22:57:42 +01:00
let nameForDisplay = NSLocalizedString("All Unread", comment: "All Unread pseudo-feed title")
let fetchType = FetchType.unread(nil)
2017-11-19 22:57:42 +01:00
var unreadCount = 0 {
didSet {
if unreadCount != oldValue {
postUnreadCountDidChangeNotification()
}
}
}
var smallIcon: IconImage? {
return AppAssets.unreadFeedImage
}
#if os(macOS)
var pasteboardWriter: NSPasteboardWriting {
return SmartFeedPasteboardWriter(smartFeed: self)
}
#endif
2024-03-20 07:05:30 +01:00
@MainActor init() {
2017-11-19 22:57:42 +01:00
self.unreadCount = appDelegate.unreadCount
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: appDelegate)
}
2024-03-20 07:05:30 +01:00
@objc @MainActor func unreadCountDidChange(_ note: Notification) {
2017-11-19 22:57:42 +01:00
assert(note.object is AppDelegate)
unreadCount = appDelegate.unreadCount
}
}
extension UnreadFeed: ArticleFetcher {
2024-03-19 05:08:37 +01:00
// Always fetches unread articles
func fetchArticles() async throws -> Set<Article> {
try await fetchUnreadArticles()
}
func fetchUnreadArticles() async throws -> Set<Article> {
try await AccountManager.shared.fetchArticles(fetchType: fetchType)
}
}