2019-10-18 23:21:02 +02:00
|
|
|
|
//
|
|
|
|
|
// FeedlyGetEntriesOperation.swift
|
|
|
|
|
// Account
|
|
|
|
|
//
|
|
|
|
|
// Created by Kiel Gillard on 28/10/19.
|
|
|
|
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
2019-11-27 09:04:55 +01:00
|
|
|
|
import os.log
|
2020-01-09 06:24:47 +01:00
|
|
|
|
import RSParser
|
2019-10-18 23:21:02 +02:00
|
|
|
|
|
2020-01-19 23:19:06 +01:00
|
|
|
|
/// Get full entries for the entry identifiers.
|
2020-01-09 06:24:47 +01:00
|
|
|
|
final class FeedlyGetEntriesOperation: FeedlyOperation, FeedlyEntryProviding, FeedlyParsedItemProviding {
|
2020-01-19 23:19:06 +01:00
|
|
|
|
|
2019-10-18 23:21:02 +02:00
|
|
|
|
let account: Account
|
|
|
|
|
let service: FeedlyGetEntriesService
|
2020-01-09 06:24:47 +01:00
|
|
|
|
let provider: FeedlyEntryIdentifierProviding
|
2019-11-27 09:04:55 +01:00
|
|
|
|
let log: OSLog
|
2020-01-19 23:19:06 +01:00
|
|
|
|
|
2020-01-09 06:24:47 +01:00
|
|
|
|
init(account: Account, service: FeedlyGetEntriesService, provider: FeedlyEntryIdentifierProviding, log: OSLog) {
|
2019-10-18 23:21:02 +02:00
|
|
|
|
self.account = account
|
|
|
|
|
self.service = service
|
|
|
|
|
self.provider = provider
|
2019-11-27 09:04:55 +01:00
|
|
|
|
self.log = log
|
2019-10-18 23:21:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private (set) var entries = [FeedlyEntry]()
|
|
|
|
|
|
2020-01-09 06:24:47 +01:00
|
|
|
|
private var storedParsedEntries: Set<ParsedItem>?
|
|
|
|
|
|
|
|
|
|
var parsedEntries: Set<ParsedItem> {
|
|
|
|
|
if let entries = storedParsedEntries {
|
|
|
|
|
return entries
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let parsed = Set(entries.compactMap {
|
|
|
|
|
FeedlyEntryParser(entry: $0).parsedItemRepresentation
|
|
|
|
|
})
|
|
|
|
|
|
2020-01-16 06:30:37 +01:00
|
|
|
|
// TODO: Fix the below. There’s an error on the os.log line: "Expression type '()' is ambiguous without more context"
|
|
|
|
|
// if parsed.count != entries.count {
|
|
|
|
|
// let entryIds = Set(entries.map { $0.id })
|
|
|
|
|
// let parsedIds = Set(parsed.map { $0.uniqueID })
|
|
|
|
|
// let difference = entryIds.subtracting(parsedIds)
|
|
|
|
|
// os_log(.debug, log: log, "%{public}@ dropping articles with ids: %{public}@.", self, difference)
|
|
|
|
|
// }
|
2020-01-09 06:24:47 +01:00
|
|
|
|
|
|
|
|
|
storedParsedEntries = parsed
|
|
|
|
|
|
|
|
|
|
return parsed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var parsedItemProviderName: String {
|
|
|
|
|
return name ?? String(describing: Self.self)
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-16 06:30:37 +01:00
|
|
|
|
override func run() {
|
2019-10-18 23:21:02 +02:00
|
|
|
|
service.getEntries(for: provider.entryIds) { result in
|
|
|
|
|
switch result {
|
|
|
|
|
case .success(let entries):
|
|
|
|
|
self.entries = entries
|
|
|
|
|
self.didFinish()
|
|
|
|
|
|
|
|
|
|
case .failure(let error):
|
2019-11-27 09:04:55 +01:00
|
|
|
|
os_log(.debug, log: self.log, "Unable to get entries: %{public}@.", error as NSError)
|
2020-01-19 23:19:06 +01:00
|
|
|
|
self.didFinish(with: error)
|
2019-10-18 23:21:02 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|