Sync highlights in search also

This commit is contained in:
Jackson Harper
2023-12-27 18:00:24 +08:00
parent e746952f65
commit 4f6f452801
3 changed files with 18 additions and 4 deletions

View File

@ -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)

View File

@ -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) ?? []
)
}

View File

@ -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 {