From 3b47edfba7ec66167820eaa40b666c7af2d0f697 Mon Sep 17 00:00:00 2001 From: Kiel Gillard Date: Mon, 30 Dec 2019 10:08:08 +1100 Subject: [PATCH] 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. --- .../Account/Feedly/Models/FeedlyEntryParser.swift | 10 +++++++--- Frameworks/Account/Feedly/Models/FeedlyOrigin.swift | 2 +- .../FeedlyGetStreamContentsOperation.swift | 12 +++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Frameworks/Account/Feedly/Models/FeedlyEntryParser.swift b/Frameworks/Account/Feedly/Models/FeedlyEntryParser.swift index 5db8b2c0c..4fe7589f3 100644 --- a/Frameworks/Account/Feedly/Models/FeedlyEntryParser.swift +++ b/Frameworks/Account/Feedly/Models/FeedlyEntryParser.swift @@ -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, diff --git a/Frameworks/Account/Feedly/Models/FeedlyOrigin.swift b/Frameworks/Account/Feedly/Models/FeedlyOrigin.swift index 3ecb6528e..dda70dc33 100644 --- a/Frameworks/Account/Feedly/Models/FeedlyOrigin.swift +++ b/Frameworks/Account/Feedly/Models/FeedlyOrigin.swift @@ -10,6 +10,6 @@ import Foundation struct FeedlyOrigin: Decodable { var title: String? - var streamId: String + var streamId: String? var htmlUrl: String } diff --git a/Frameworks/Account/Feedly/Operations/FeedlyGetStreamContentsOperation.swift b/Frameworks/Account/Feedly/Operations/FeedlyGetStreamContentsOperation.swift index 40bb6080b..db8c1a201 100644 --- a/Frameworks/Account/Feedly/Operations/FeedlyGetStreamContentsOperation.swift +++ b/Frameworks/Account/Feedly/Operations/FeedlyGetStreamContentsOperation.swift @@ -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