mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
update highlights on linkedItem when persisting
This commit is contained in:
parent
753eb56542
commit
61c7403d24
2 changed files with 9 additions and 2 deletions
|
|
@ -85,9 +85,10 @@ extension DataService {
|
|||
let linkedItem = try? self.backgroundContext.fetch(fetchRequest).first
|
||||
|
||||
if let linkedItem = linkedItem, let linkedItemID = linkedItem.id {
|
||||
_ = highlights.map {
|
||||
let highlightObjects = highlights.map {
|
||||
$0.asManagedObject(context: self.backgroundContext, associatedItemID: linkedItemID)
|
||||
}
|
||||
linkedItem.addToHighlights(NSSet(array: highlightObjects))
|
||||
linkedItem.htmlContent = htmlContent
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,13 @@ struct InternalHighlight: Encodable {
|
|||
let createdByMe: Bool
|
||||
|
||||
func asManagedObject(context: NSManagedObjectContext, associatedItemID: String) -> Highlight {
|
||||
let highlight = Highlight(entity: Highlight.entity(), insertInto: context)
|
||||
let fetchRequest: NSFetchRequest<Models.Highlight> = Highlight.fetchRequest()
|
||||
fetchRequest.predicate = NSPredicate(
|
||||
format: "id == %@", id
|
||||
)
|
||||
let existingHighlight = (try? context.fetch(fetchRequest))?.first
|
||||
let highlight = existingHighlight ?? Highlight(entity: Highlight.entity(), insertInto: context)
|
||||
|
||||
highlight.linkedItemId = associatedItemID
|
||||
highlight.markedForDeletion = false
|
||||
highlight.id = id
|
||||
|
|
|
|||
Loading…
Reference in a new issue