Change to respect individual feed filters when multiple feeds are selected. Issue #2399
This commit is contained in:
parent
35175fed27
commit
feba4a7bc6
|
@ -20,3 +20,19 @@ public protocol Feed: FeedIdentifiable, ArticleFetcher, DisplayNameProvider, Unr
|
|||
var defaultReadFilterType: ReadFilterType { get }
|
||||
|
||||
}
|
||||
|
||||
public extension Feed {
|
||||
|
||||
func readFiltered(readFilterEnabledTable: [FeedIdentifier: Bool]) -> Bool {
|
||||
guard defaultReadFilterType != .alwaysRead else {
|
||||
return true
|
||||
}
|
||||
if let feedID = feedID, let readFilterEnabled = readFilterEnabledTable[feedID] {
|
||||
return readFilterEnabled
|
||||
} else {
|
||||
return defaultReadFilterType == .read
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1129,19 +1129,19 @@ private extension TimelineViewController {
|
|||
|
||||
func fetchUnsortedArticlesSync(for representedObjects: [Any]) -> Set<Article> {
|
||||
cancelPendingAsyncFetches()
|
||||
let articleFetchers = representedObjects.compactMap{ $0 as? ArticleFetcher }
|
||||
if articleFetchers.isEmpty {
|
||||
let feeds = representedObjects.compactMap{ $0 as? Feed }
|
||||
if feeds.isEmpty {
|
||||
return Set<Article>()
|
||||
}
|
||||
|
||||
var fetchedArticles = Set<Article>()
|
||||
for articleFetcher in articleFetchers {
|
||||
if isReadFiltered ?? true {
|
||||
if let articles = try? articleFetcher.fetchUnreadArticles() {
|
||||
for feed in feeds {
|
||||
if feed.readFiltered(readFilterEnabledTable: readFilterEnabledTable) {
|
||||
if let articles = try? feed.fetchUnreadArticles() {
|
||||
fetchedArticles.formUnion(articles)
|
||||
}
|
||||
} else {
|
||||
if let articles = try? articleFetcher.fetchArticles() {
|
||||
if let articles = try? feed.fetchArticles() {
|
||||
fetchedArticles.formUnion(articles)
|
||||
}
|
||||
}
|
||||
|
@ -1154,7 +1154,8 @@ private extension TimelineViewController {
|
|||
// if it’s been superseded by a newer fetch, or the timeline was emptied, etc., it won’t get called.
|
||||
precondition(Thread.isMainThread)
|
||||
cancelPendingAsyncFetches()
|
||||
let fetchOperation = FetchRequestOperation(id: fetchSerialNumber, readFilter: isReadFiltered ?? true, representedObjects: representedObjects) { [weak self] (articles, operation) in
|
||||
let feeds = representedObjects.compactMap { $0 as? Feed }
|
||||
let fetchOperation = FetchRequestOperation(id: fetchSerialNumber, readFilterEnabledTable: readFilterEnabledTable, feeds: feeds) { [weak self] (articles, operation) in
|
||||
precondition(Thread.isMainThread)
|
||||
guard !operation.isCanceled, let strongSelf = self, operation.id == strongSelf.fetchSerialNumber else {
|
||||
return
|
||||
|
|
|
@ -19,17 +19,17 @@ typealias FetchRequestOperationResultBlock = (Set<Article>, FetchRequestOperatio
|
|||
final class FetchRequestOperation {
|
||||
|
||||
let id: Int
|
||||
let readFilter: Bool
|
||||
let readFilterEnabledTable: [FeedIdentifier: Bool]
|
||||
let resultBlock: FetchRequestOperationResultBlock
|
||||
var isCanceled = false
|
||||
var isFinished = false
|
||||
private let representedObjects: [Any]
|
||||
private let feeds: [Feed]
|
||||
|
||||
init(id: Int, readFilter: Bool, representedObjects: [Any], resultBlock: @escaping FetchRequestOperationResultBlock) {
|
||||
init(id: Int, readFilterEnabledTable: [FeedIdentifier: Bool], feeds: [Feed], resultBlock: @escaping FetchRequestOperationResultBlock) {
|
||||
precondition(Thread.isMainThread)
|
||||
self.id = id
|
||||
self.readFilter = readFilter
|
||||
self.representedObjects = representedObjects
|
||||
self.readFilterEnabledTable = readFilterEnabledTable
|
||||
self.feeds = feeds
|
||||
self.resultBlock = resultBlock
|
||||
}
|
||||
|
||||
|
@ -51,15 +51,14 @@ final class FetchRequestOperation {
|
|||
return
|
||||
}
|
||||
|
||||
let articleFetchers = representedObjects.compactMap{ $0 as? ArticleFetcher }
|
||||
if articleFetchers.isEmpty {
|
||||
if feeds.isEmpty {
|
||||
isFinished = true
|
||||
resultBlock(Set<Article>(), self)
|
||||
callCompletionIfNeeded()
|
||||
return
|
||||
}
|
||||
|
||||
let numberOfFetchers = articleFetchers.count
|
||||
let numberOfFetchers = feeds.count
|
||||
var fetchersReturned = 0
|
||||
var fetchedArticles = Set<Article>()
|
||||
|
||||
|
@ -81,15 +80,15 @@ final class FetchRequestOperation {
|
|||
}
|
||||
}
|
||||
|
||||
for articleFetcher in articleFetchers {
|
||||
if readFilter {
|
||||
articleFetcher.fetchUnreadArticlesAsync { articleSetResult in
|
||||
for feed in feeds {
|
||||
if feed.readFiltered(readFilterEnabledTable: readFilterEnabledTable) {
|
||||
feed.fetchUnreadArticlesAsync { articleSetResult in
|
||||
let articles = (try? articleSetResult.get()) ?? Set<Article>()
|
||||
process(articles)
|
||||
}
|
||||
}
|
||||
else {
|
||||
articleFetcher.fetchArticlesAsync { articleSetResult in
|
||||
feed.fetchArticlesAsync { articleSetResult in
|
||||
let articles = (try? articleSetResult.get()) ?? Set<Article>()
|
||||
process(articles)
|
||||
}
|
||||
|
|
|
@ -1906,7 +1906,8 @@ private extension SceneCoordinator {
|
|||
precondition(Thread.isMainThread)
|
||||
cancelPendingAsyncFetches()
|
||||
|
||||
let fetchOperation = FetchRequestOperation(id: fetchSerialNumber, readFilter: isReadArticlesFiltered, representedObjects: representedObjects) { [weak self] (articles, operation) in
|
||||
let feeds = representedObjects.compactMap { $0 as? Feed }
|
||||
let fetchOperation = FetchRequestOperation(id: fetchSerialNumber, readFilterEnabledTable: readFilterEnabledTable, feeds: feeds) { [weak self] (articles, operation) in
|
||||
precondition(Thread.isMainThread)
|
||||
guard !operation.isCanceled, let strongSelf = self, operation.id == strongSelf.fetchSerialNumber else {
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue