Models the feed identifier of feedly articles as an optional since it seems the Feedly API will not always provide one (despite the API documentation).

Additional, more elegantly handle the failure to parse an article when Feedly does not provide a matching feed.
This commit is contained in:
Kiel Gillard 2019-12-30 10:08:08 +11:00
parent c692d46cc8
commit 3b47edfba7
3 changed files with 19 additions and 5 deletions

View File

@ -17,10 +17,10 @@ struct FeedlyEntryParser {
return entry.id
}
var feedUrl: String {
var feedUrl: String? {
guard let id = entry.origin?.streamId else {
assertionFailure()
return ""
return nil
}
return id
}
@ -82,7 +82,11 @@ struct FeedlyEntryParser {
return attachments.isEmpty ? nil : Set(attachments)
}
var parsedItemRepresentation: ParsedItem {
var parsedItemRepresentation: ParsedItem? {
guard let feedUrl = feedUrl else {
return nil
}
return ParsedItem(syncServiceID: id,
uniqueID: id, // This value seems to get ignored or replaced.
feedURL: feedUrl,

View File

@ -10,6 +10,6 @@ import Foundation
struct FeedlyOrigin: Decodable {
var title: String?
var streamId: String
var streamId: String?
var htmlUrl: String
}

View File

@ -50,7 +50,17 @@ final class FeedlyGetStreamContentsOperation: FeedlyOperation, FeedlyEntryProvid
return entries
}
let parsed = Set(entries.map { FeedlyEntryParser(entry: $0).parsedItemRepresentation })
let parsed = Set(entries.compactMap {
FeedlyEntryParser(entry: $0).parsedItemRepresentation
})
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, "Dropping articles with ids: %{public}@.", difference)
}
storedParsedEntries = parsed
return parsed