Update appropriate counts in the sidebar when the timeline’s unread count changes. Fix #829.
This commit is contained in:
parent
fc0fc2055e
commit
2bbd135c9e
|
@ -455,7 +455,7 @@ extension MainWindowController: NSSearchFieldDelegate {
|
|||
return
|
||||
}
|
||||
lastSentSearchString = searchString
|
||||
let smartFeed = SmartFeed(delegate: SearchFeedDelegate(searchString: searchString), type: .search)
|
||||
let smartFeed = SmartFeed(delegate: SearchFeedDelegate(searchString: searchString))
|
||||
timelineContainerViewController?.setRepresentedObjects([smartFeed], mode: .search)
|
||||
searchSmartFeed = smartFeed
|
||||
}
|
||||
|
|
|
@ -83,7 +83,12 @@ protocol SidebarDelegate: class {
|
|||
guard let representedObject = note.object else {
|
||||
return
|
||||
}
|
||||
configureUnreadCountForCellsForRepresentedObject(representedObject as AnyObject)
|
||||
if let timelineViewController = representedObject as? TimelineViewController {
|
||||
configureUnreadCountForCellsForRepresentedObjects(timelineViewController.representedObjects)
|
||||
}
|
||||
else {
|
||||
configureUnreadCountForCellsForRepresentedObjects([representedObject as AnyObject])
|
||||
}
|
||||
}
|
||||
|
||||
@objc func containerChildrenDidChange(_ note: Notification) {
|
||||
|
@ -499,7 +504,6 @@ private extension SidebarViewController {
|
|||
|
||||
func unreadCountFor(_ node: Node) -> Int {
|
||||
// If this node is the one and only selection,
|
||||
// and it’s the Today feed,
|
||||
// then the unread count comes from the timeline.
|
||||
// This ensures that any transients in the timeline
|
||||
// are accounted for in the unread count.
|
||||
|
@ -514,18 +518,15 @@ private extension SidebarViewController {
|
|||
}
|
||||
|
||||
func nodeShouldGetUnreadCountFromTimeline(_ node: Node) -> Bool {
|
||||
// Only if it’s selected, it’s the only node selected,
|
||||
// and it’s the Today feed — which may have transients that are unread.
|
||||
if selectedNodes.count != 1 {
|
||||
return false
|
||||
}
|
||||
if node !== selectedNodes.first! {
|
||||
return false
|
||||
}
|
||||
// Only if it’s selected and it’s the only node selected.
|
||||
return selectedNodes.count == 1 && selectedNodes.first! === node
|
||||
}
|
||||
|
||||
func nodeRepresentsTodayFeed(_ node: Node) -> Bool {
|
||||
guard let smartFeed = node.representedObject as? SmartFeed else {
|
||||
return false
|
||||
}
|
||||
return smartFeed.type == .today
|
||||
return smartFeed === SmartFeedsController.shared.todayFeed
|
||||
}
|
||||
|
||||
func cellForRowView(_ rowView: NSTableRowView) -> SidebarCell? {
|
||||
|
@ -553,8 +554,13 @@ private extension SidebarViewController {
|
|||
applyToCellsForRepresentedObject(representedObject, configure)
|
||||
}
|
||||
|
||||
func configureUnreadCountForCellsForRepresentedObject(_ representedObject: AnyObject) {
|
||||
applyToCellsForRepresentedObject(representedObject, configureUnreadCount)
|
||||
func configureUnreadCountForCellsForRepresentedObjects(_ representedObjects: [AnyObject]?) {
|
||||
guard let representedObjects = representedObjects else {
|
||||
return
|
||||
}
|
||||
for object in representedObjects {
|
||||
applyToCellsForRepresentedObject(object, configureUnreadCount)
|
||||
}
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
|
|
|
@ -11,22 +11,12 @@ import RSCore
|
|||
import Articles
|
||||
import Account
|
||||
|
||||
enum SmartFeedType {
|
||||
case today
|
||||
case allUnread
|
||||
case starred
|
||||
case search
|
||||
case custom
|
||||
}
|
||||
|
||||
final class SmartFeed: PseudoFeed {
|
||||
|
||||
var nameForDisplay: String {
|
||||
return delegate.nameForDisplay
|
||||
}
|
||||
|
||||
let type: SmartFeedType
|
||||
|
||||
var unreadCount = 0 {
|
||||
didSet {
|
||||
if unreadCount != oldValue {
|
||||
|
@ -44,9 +34,8 @@ final class SmartFeed: PseudoFeed {
|
|||
private let delegate: SmartFeedDelegate
|
||||
private var unreadCounts = [String: Int]()
|
||||
|
||||
init(delegate: SmartFeedDelegate, type: SmartFeedType) {
|
||||
init(delegate: SmartFeedDelegate) {
|
||||
self.delegate = delegate
|
||||
self.type = type
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||
queueFetchUnreadCounts() // Fetch unread count at startup
|
||||
}
|
||||
|
|
|
@ -15,9 +15,9 @@ final class SmartFeedsController: DisplayNameProvider {
|
|||
let nameForDisplay = NSLocalizedString("Smart Feeds", comment: "Smart Feeds group title")
|
||||
|
||||
var smartFeeds = [AnyObject]()
|
||||
let todayFeed = SmartFeed(delegate: TodayFeedDelegate(), type: .today)
|
||||
let todayFeed = SmartFeed(delegate: TodayFeedDelegate())
|
||||
let unreadFeed = UnreadFeed()
|
||||
let starredFeed = SmartFeed(delegate: StarredFeedDelegate(), type: .starred)
|
||||
let starredFeed = SmartFeed(delegate: StarredFeedDelegate())
|
||||
|
||||
private init() {
|
||||
|
||||
|
|
Loading…
Reference in New Issue