2017-11-19 13:57:42 -08:00
|
|
|
//
|
|
|
|
// UnreadFeed.swift
|
2018-08-28 22:18:24 -07:00
|
|
|
// NetNewsWire
|
2017-11-19 13:57:42 -08:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 11/19/17.
|
|
|
|
// Copyright © 2017 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2019-04-15 15:03:05 -05:00
|
|
|
#if os(macOS)
|
2018-02-11 22:10:28 -08:00
|
|
|
import AppKit
|
2019-04-15 15:03:05 -05:00
|
|
|
#else
|
|
|
|
import Foundation
|
|
|
|
#endif
|
2018-02-10 13:00:53 -08:00
|
|
|
import Account
|
2018-07-23 18:29:08 -07:00
|
|
|
import Articles
|
2019-12-16 22:45:59 -08:00
|
|
|
import ArticlesDatabase
|
2024-04-15 22:21:17 -07:00
|
|
|
import Images
|
2017-11-19 13:57:42 -08:00
|
|
|
|
|
|
|
// This just shows the global unread count, which appDelegate already has. Easy.
|
|
|
|
|
|
|
|
final class UnreadFeed: PseudoFeed {
|
2021-10-20 19:03:02 -05:00
|
|
|
|
|
|
|
var account: Account? = nil
|
2017-11-19 13:57:42 -08:00
|
|
|
|
2024-02-26 08:12:34 -08:00
|
|
|
var defaultReadFilterType: ReadFilterType {
|
2019-11-22 09:32:27 -06:00
|
|
|
return .alwaysRead
|
2019-11-21 18:22:43 -06:00
|
|
|
}
|
|
|
|
|
2024-02-25 21:34:22 -08:00
|
|
|
var sidebarItemID: SidebarItemIdentifier? {
|
2024-02-25 21:17:00 -08:00
|
|
|
return SidebarItemIdentifier.smartFeed(String(describing: UnreadFeed.self))
|
2019-11-15 06:19:14 -06:00
|
|
|
}
|
|
|
|
|
2017-11-19 13:57:42 -08:00
|
|
|
let nameForDisplay = NSLocalizedString("All Unread", comment: "All Unread pseudo-feed title")
|
2021-03-24 05:43:07 -05:00
|
|
|
let fetchType = FetchType.unread(nil)
|
2019-07-05 20:06:31 -07:00
|
|
|
|
2017-11-19 13:57:42 -08:00
|
|
|
var unreadCount = 0 {
|
|
|
|
didSet {
|
|
|
|
if unreadCount != oldValue {
|
|
|
|
postUnreadCountDidChangeNotification()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-06 16:01:43 -06:00
|
|
|
var smallIcon: IconImage? {
|
|
|
|
return AppAssets.unreadFeedImage
|
|
|
|
}
|
2019-09-17 20:26:49 -05:00
|
|
|
|
2019-04-15 15:03:05 -05:00
|
|
|
#if os(macOS)
|
2018-02-11 22:10:28 -08:00
|
|
|
var pasteboardWriter: NSPasteboardWriting {
|
|
|
|
return SmartFeedPasteboardWriter(smartFeed: self)
|
|
|
|
}
|
2019-04-15 15:03:05 -05:00
|
|
|
#endif
|
2018-02-11 22:10:28 -08:00
|
|
|
|
2024-03-19 23:05:30 -07:00
|
|
|
@MainActor init() {
|
2017-11-19 13:57:42 -08:00
|
|
|
|
|
|
|
self.unreadCount = appDelegate.unreadCount
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: appDelegate)
|
|
|
|
}
|
|
|
|
|
2024-03-19 23:05:30 -07:00
|
|
|
@objc @MainActor func unreadCountDidChange(_ note: Notification) {
|
2017-11-19 13:57:42 -08:00
|
|
|
|
|
|
|
assert(note.object is AppDelegate)
|
|
|
|
unreadCount = appDelegate.unreadCount
|
|
|
|
}
|
|
|
|
}
|
2018-02-10 13:00:53 -08:00
|
|
|
|
|
|
|
extension UnreadFeed: ArticleFetcher {
|
2019-11-14 15:06:32 -06:00
|
|
|
|
2024-03-18 21:08:37 -07: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)
|
|
|
|
}
|
2018-02-10 13:00:53 -08:00
|
|
|
}
|