From 4f6f45280141225a32fea249d1bd30ae2884c735 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 27 Dec 2023 18:00:24 +0800 Subject: [PATCH] Sync highlights in search also --- .../DataService/Queries/ArticleContentQuery.swift | 3 ++- .../Queries/LinkedItemNetworkQuery.swift | 6 ++++-- .../InternalModels/InternalLibraryItem.swift | 13 ++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Queries/ArticleContentQuery.swift b/apple/OmnivoreKit/Sources/Services/DataService/Queries/ArticleContentQuery.swift index 39e4df777..6bb4bd655 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Queries/ArticleContentQuery.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Queries/ArticleContentQuery.swift @@ -49,7 +49,8 @@ extension DataService { wordsCount: try $0.wordsCount(), downloadURL: try $0.url(), recommendations: try $0.recommendations(selection: recommendationSelection.list.nullable) ?? [], - labels: try $0.labels(selection: feedItemLabelSelection.list.nullable) ?? [] + labels: try $0.labels(selection: feedItemLabelSelection.list.nullable) ?? [], + highlights: try $0.highlights(selection: highlightSelection.list) ), htmlContent: try $0.content(), highlights: try $0.highlights(selection: highlightSelection.list) diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Queries/LinkedItemNetworkQuery.swift b/apple/OmnivoreKit/Sources/Services/DataService/Queries/LinkedItemNetworkQuery.swift index 103a67816..4403b4ef3 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Queries/LinkedItemNetworkQuery.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Queries/LinkedItemNetworkQuery.swift @@ -291,7 +291,8 @@ private let libraryArticleSelection = Selection.Article { wordsCount: try $0.wordsCount(), downloadURL: try $0.url(), recommendations: try $0.recommendations(selection: recommendationSelection.list.nullable) ?? [], - labels: try $0.labels(selection: feedItemLabelSelection.list.nullable) ?? [] + labels: try $0.labels(selection: feedItemLabelSelection.list.nullable) ?? [], + highlights: try $0.highlights(selection: highlightSelection.list) ?? [] ) } @@ -334,7 +335,8 @@ private let searchItemSelection = Selection.SearchItem { wordsCount: try $0.wordsCount(), downloadURL: try $0.url(), recommendations: try $0.recommendations(selection: recommendationSelection.list.nullable) ?? [], - labels: try $0.labels(selection: feedItemLabelSelection.list.nullable) ?? [] + labels: try $0.labels(selection: feedItemLabelSelection.list.nullable) ?? [], + highlights: try $0.highlights(selection: highlightSelection.list.nullable) ?? [] ) } diff --git a/apple/OmnivoreKit/Sources/Services/InternalModels/InternalLibraryItem.swift b/apple/OmnivoreKit/Sources/Services/InternalModels/InternalLibraryItem.swift index 5372e7625..3a2a4e0e9 100644 --- a/apple/OmnivoreKit/Sources/Services/InternalModels/InternalLibraryItem.swift +++ b/apple/OmnivoreKit/Sources/Services/InternalModels/InternalLibraryItem.swift @@ -32,6 +32,7 @@ struct InternalLibraryItem { let downloadURL: String let recommendations: [InternalRecommendation] var labels: [InternalLinkedItemLabel] + var highlights: [InternalHighlight] var isPDF: Bool { if let contentReader = contentReader { @@ -89,6 +90,15 @@ struct InternalLibraryItem { linkedItem.addToRecommendations(recommendation.asManagedObject(inContext: context)) } + // Remove existing labels in case a label had been deleted + if let existingHighlights = linkedItem.highlights { + linkedItem.removeFromHighlights(existingHighlights) + } + + for highlight in highlights { + linkedItem.addToHighlights(highlight.asManagedObject(context: context)) + } + return linkedItem } } @@ -156,7 +166,8 @@ extension JSONArticle { wordsCount: wordsCount, downloadURL: downloadURL, recommendations: [], - labels: [] + labels: [], + highlights: [] ) context.performAndWait {