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