Add code for fetching articles for the timeline. Doesn’t actually work yet, though, for some reason.
This commit is contained in:
parent
4b662efe15
commit
8aa3746cb8
|
@ -367,64 +367,46 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView
|
|||
|
||||
private func articleComparator(_ article1: Article, article2: Article) -> Bool {
|
||||
|
||||
return article1.logicalDatePublished.compare(article2.logicalDatePublished) == .orderedDescending
|
||||
return article1.logicalDatePublished < article2.logicalDatePublished
|
||||
}
|
||||
|
||||
private func articlesSortedByDate(_ articles: Set<Article>) -> [Article] {
|
||||
|
||||
return Array(articles).sorted(by: articleComparator)
|
||||
}
|
||||
|
||||
// MARK: Fetching Articles
|
||||
|
||||
private func emptyTheTimeline() {
|
||||
|
||||
if !articles.isEmpty {
|
||||
articles = [Article]()
|
||||
}
|
||||
}
|
||||
|
||||
private func fetchArticles() {
|
||||
|
||||
// guard let representedObjects = representedObjects else {
|
||||
// if !articles.isEmpty {
|
||||
// articles = [Article]()
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// var accountsDictionary = [String: [AnyObject]]()
|
||||
//
|
||||
// func addToAccountArray(accountID: String, object: AnyObject) {
|
||||
//
|
||||
// if let accountArray = accountsDictionary[accountID] {
|
||||
// if !accountArray.contains(where: { $0 === object }) {
|
||||
// accountsDictionary[accountID] = accountArray + [object]
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// accountsDictionary[accountID] = [object]
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for oneObject in representedObjects {
|
||||
//
|
||||
// if let oneFeed = oneObject as? Feed {
|
||||
// addToAccountArray(accountID: oneFeed.account.accountID, object: oneFeed)
|
||||
// }
|
||||
// else if let oneFolder = oneObject as? Folder, let accountID = oneFolder.account?.accountID {
|
||||
// addToAccountArray(accountID: accountID, object: oneFolder)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// var fetchedArticles = [Article]()
|
||||
// for (accountID, objects) in accountsDictionary {
|
||||
//
|
||||
// guard let oneAccount = accountWithID(accountID) else {
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// let oneFetchedArticles = oneAccount.fetchArticles(for: objects)
|
||||
// for oneFetchedArticle in oneFetchedArticles {
|
||||
// if !fetchedArticles.contains(where: { $0 === oneFetchedArticle }) {
|
||||
// fetchedArticles += [oneFetchedArticle]
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fetchedArticles.sort(by: articleComparator)
|
||||
//
|
||||
// if articles != fetchedArticles {
|
||||
// articles = fetchedArticles
|
||||
// }
|
||||
guard let representedObjects = representedObjects else {
|
||||
emptyTheTimeline()
|
||||
return
|
||||
}
|
||||
|
||||
var fetchedArticles = Set<Article>()
|
||||
|
||||
for object in representedObjects {
|
||||
|
||||
if let feed = object as? Feed {
|
||||
fetchedArticles.formUnion(feed.fetchArticles())
|
||||
}
|
||||
else if let folder = object as? Folder {
|
||||
fetchedArticles.formUnion(folder.fetchArticles())
|
||||
}
|
||||
}
|
||||
|
||||
let sortedArticles = articlesSortedByDate(fetchedArticles)
|
||||
if articles != sortedArticles {
|
||||
articles = sortedArticles
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Cell Configuring
|
||||
|
|
|
@ -242,6 +242,16 @@ public final class Account: DisplayNameProvider, Container, Hashable {
|
|||
}
|
||||
}
|
||||
|
||||
public func fetchArticles(for feed: Feed) -> Set<Article> {
|
||||
|
||||
return database.fetchArticles(for: feed)
|
||||
}
|
||||
|
||||
public func fetchArticles(folder: Folder) -> Set<Article> {
|
||||
|
||||
return database.fetchUnreadArticles(for: folder.flattenedFeeds())
|
||||
}
|
||||
|
||||
// MARK: - Notifications
|
||||
|
||||
@objc func downloadProgressDidChange(_ note: Notification) {
|
||||
|
|
|
@ -208,16 +208,20 @@ private struct AccountSpecifier {
|
|||
|
||||
init?(folderPath: String) {
|
||||
|
||||
self.folderPath = folderPath
|
||||
self.folderName = NSString(string: folderPath).lastPathComponent
|
||||
|
||||
let nameComponents = self.folderName.components(separatedBy: "-")
|
||||
let satisfyCompilerFolderName = self.folderName
|
||||
assert(nameComponents.count == 2, "Can’t determine account info from \(satisfyCompilerFolderName)")
|
||||
if !FileManager.default.rs_fileIsFolder(folderPath) {
|
||||
return nil
|
||||
}
|
||||
let name = NSString(string: folderPath).lastPathComponent
|
||||
if name.hasPrefix(".") {
|
||||
return nil
|
||||
}
|
||||
let nameComponents = name.components(separatedBy: "-")
|
||||
if nameComponents.count != 2 {
|
||||
return nil
|
||||
}
|
||||
|
||||
self.folderPath = folderPath
|
||||
self.folderName = name
|
||||
self.type = nameComponents[0]
|
||||
self.identifier = nameComponents[1]
|
||||
|
||||
|
|
|
@ -11,11 +11,20 @@ import Data
|
|||
|
||||
public extension Feed {
|
||||
|
||||
var account: Account? {
|
||||
public var account: Account? {
|
||||
get {
|
||||
return AccountManager.shared.existingAccount(with: accountID)
|
||||
}
|
||||
}
|
||||
|
||||
public func fetchArticles() -> Set<Article> {
|
||||
|
||||
guard let account = account else {
|
||||
assertionFailure("Expected feed.account.")
|
||||
return Set<Article>()
|
||||
}
|
||||
return account.fetchArticles(for: self)
|
||||
}
|
||||
}
|
||||
|
||||
public extension Article {
|
||||
|
|
|
@ -16,6 +16,13 @@ public final class Folder: DisplayNameProvider, Container, UnreadCountProvider {
|
|||
var name: String?
|
||||
static let untitledName = NSLocalizedString("Untitled ƒ", comment: "Folder name")
|
||||
|
||||
// MARK: - Fetching Articles
|
||||
|
||||
public func fetchArticles() -> Set<Article> {
|
||||
|
||||
return account.fetchArticles(folder: self)
|
||||
}
|
||||
|
||||
// MARK: - DisplayNameProvider
|
||||
|
||||
public var nameForDisplay: String {
|
||||
|
|
Loading…
Reference in New Issue