2020-06-16 01:03:20 +02:00
|
|
|
//
|
|
|
|
// MasterFeedTableViewIdentifier.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 6/3/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Account
|
|
|
|
import RSTree
|
|
|
|
|
|
|
|
final class MasterFeedTableViewIdentifier: NSObject, NSCopying {
|
|
|
|
|
|
|
|
let feedID: FeedIdentifier?
|
|
|
|
let containerID: ContainerIdentifier?
|
|
|
|
let parentContainerID: ContainerIdentifier?
|
|
|
|
|
|
|
|
let isEditable: Bool
|
|
|
|
let isPsuedoFeed: Bool
|
|
|
|
let isFolder: Bool
|
|
|
|
let isWebFeed: Bool
|
|
|
|
|
|
|
|
let nameForDisplay: String
|
|
|
|
let url: String?
|
|
|
|
let unreadCount: Int
|
|
|
|
let childCount: Int
|
|
|
|
|
2020-11-01 02:14:50 +01:00
|
|
|
var account: Account? {
|
|
|
|
if isFolder, let parentContainerID = parentContainerID {
|
|
|
|
return AccountManager.shared.existingContainer(with: parentContainerID) as? Account
|
|
|
|
}
|
|
|
|
if isWebFeed, let feedID = feedID {
|
|
|
|
return (AccountManager.shared.existingFeed(with: feedID) as? WebFeed)?.account
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-16 01:03:20 +02:00
|
|
|
init(node: Node, unreadCount: Int) {
|
|
|
|
let feed = node.representedObject as! Feed
|
|
|
|
self.feedID = feed.feedID
|
|
|
|
self.containerID = (node.representedObject as? Container)?.containerID
|
|
|
|
self.parentContainerID = (node.parent?.representedObject as? Container)?.containerID
|
|
|
|
|
|
|
|
self.isEditable = !(node.representedObject is PseudoFeed)
|
|
|
|
self.isPsuedoFeed = node.representedObject is PseudoFeed
|
|
|
|
self.isFolder = node.representedObject is Folder
|
|
|
|
self.isWebFeed = node.representedObject is WebFeed
|
|
|
|
self.nameForDisplay = feed.nameForDisplay
|
|
|
|
|
|
|
|
if let webFeed = node.representedObject as? WebFeed {
|
|
|
|
self.url = webFeed.url
|
|
|
|
} else {
|
|
|
|
self.url = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
self.unreadCount = unreadCount
|
|
|
|
self.childCount = node.numberOfChildNodes
|
|
|
|
}
|
|
|
|
|
|
|
|
override func isEqual(_ object: Any?) -> Bool {
|
|
|
|
guard let otherIdentifier = object as? MasterFeedTableViewIdentifier else { return false }
|
|
|
|
if self === otherIdentifier { return true }
|
2020-07-12 14:28:38 +02:00
|
|
|
return feedID == otherIdentifier.feedID && parentContainerID == otherIdentifier.parentContainerID
|
2020-06-16 01:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override var hash: Int {
|
2020-07-12 14:28:38 +02:00
|
|
|
var hasher = Hasher()
|
|
|
|
hasher.combine(feedID)
|
|
|
|
hasher.combine(parentContainerID)
|
|
|
|
return hasher.finalize()
|
2020-06-16 01:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func copy(with zone: NSZone? = nil) -> Any {
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|