From 60a663e9bb79d03f8344d0c1f4e0c498135da4c0 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 16 Nov 2022 15:33:22 +0800 Subject: [PATCH] Make sure deleted highlights are synced to iOS --- .../Sources/Services/DataService/ContentLoading.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apple/OmnivoreKit/Sources/Services/DataService/ContentLoading.swift b/apple/OmnivoreKit/Sources/Services/DataService/ContentLoading.swift index db17d6e9c..4de282df4 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/ContentLoading.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/ContentLoading.swift @@ -110,7 +110,15 @@ extension DataService { let highlightObjects = articleProps.highlights.map { $0.asManagedObject(context: self.backgroundContext) } - linkedItem.addToHighlights(NSSet(array: highlightObjects)) + + let unsyncedHighlights = existingItem?.highlights?.filter { highlight in + if let highlight = highlight as? Highlight, highlight.serverSyncStatus == ServerSyncStatus.isNSync.rawValue { + return false + } + return true + }.compactMap { $0 as? Highlight } ?? [] + + linkedItem.highlights = NSSet(array: highlightObjects + unsyncedHighlights) linkedItem.htmlContent = articleProps.htmlContent linkedItem.id = articleProps.item.id linkedItem.state = articleProps.item.state.rawValue