mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
remove PersistedArticleContent entity
This commit is contained in:
parent
b601281166
commit
ba152b8f0a
4 changed files with 21 additions and 54 deletions
|
|
@ -24,19 +24,18 @@ final class WebReaderViewModel: ObservableObject {
|
|||
|
||||
if let content = dataService.pageFromCache(slug: slug) {
|
||||
articleContent = content
|
||||
// continue to load from the web if possible
|
||||
} else {
|
||||
dataService.articleContentPublisher(username: username, slug: slug).sink(
|
||||
receiveCompletion: { [weak self] completion in
|
||||
guard case .failure = completion else { return }
|
||||
self?.isLoading = false
|
||||
},
|
||||
receiveValue: { [weak self] articleContent in
|
||||
self?.articleContent = articleContent
|
||||
}
|
||||
)
|
||||
.store(in: &subscriptions)
|
||||
}
|
||||
|
||||
dataService.articleContentPublisher(username: username, slug: slug).sink(
|
||||
receiveCompletion: { [weak self] completion in
|
||||
guard case .failure = completion else { return }
|
||||
self?.isLoading = false
|
||||
},
|
||||
receiveValue: { [weak self] articleContent in
|
||||
self?.articleContent = articleContent
|
||||
}
|
||||
)
|
||||
.store(in: &subscriptions)
|
||||
}
|
||||
|
||||
func createHighlight(
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
<attribute name="contentReader" optional="YES" attributeType="String"/>
|
||||
<attribute name="createdAt" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="descriptionText" optional="YES" attributeType="String"/>
|
||||
<attribute name="htmlContent" optional="YES" attributeType="String"/>
|
||||
<attribute name="id" attributeType="String"/>
|
||||
<attribute name="imageURLString" optional="YES" attributeType="String"/>
|
||||
<attribute name="isArchived" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
|
|
@ -67,15 +68,6 @@
|
|||
</uniquenessConstraint>
|
||||
</uniquenessConstraints>
|
||||
</entity>
|
||||
<entity name="PersistedArticleContent" representedClassName="PersistedArticleContent" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="htmlContent" attributeType="String"/>
|
||||
<attribute name="slug" attributeType="String"/>
|
||||
<uniquenessConstraints>
|
||||
<uniquenessConstraint>
|
||||
<constraint value="slug"/>
|
||||
</uniquenessConstraint>
|
||||
</uniquenessConstraints>
|
||||
</entity>
|
||||
<entity name="Viewer" representedClassName="Viewer" syncable="YES" codeGenerationType="class">
|
||||
<attribute name="name" attributeType="String"/>
|
||||
<attribute name="profileImageURL" optional="YES" attributeType="String"/>
|
||||
|
|
@ -89,10 +81,9 @@
|
|||
</entity>
|
||||
<elements>
|
||||
<element name="Highlight" positionX="27" positionY="225" width="128" height="224"/>
|
||||
<element name="LinkedItem" positionX="-18" positionY="63" width="128" height="299"/>
|
||||
<element name="LinkedItem" positionX="-18" positionY="63" width="128" height="314"/>
|
||||
<element name="LinkedItemLabel" positionX="-36" positionY="18" width="128" height="104"/>
|
||||
<element name="NewsletterEmail" positionX="0" positionY="180" width="128" height="74"/>
|
||||
<element name="PersistedArticleContent" positionX="9" positionY="108" width="128" height="59"/>
|
||||
<element name="Viewer" positionX="45" positionY="234" width="128" height="89"/>
|
||||
</elements>
|
||||
</model>
|
||||
|
|
@ -83,6 +83,7 @@ public extension DataService {
|
|||
)
|
||||
|
||||
guard let linkedItem = try? persistentContainer.viewContext.fetch(linkedItemFetchRequest).first else { return nil }
|
||||
guard let htmlContent = linkedItem.htmlContent else { return nil }
|
||||
|
||||
let highlightsFetchRequest: NSFetchRequest<Models.Highlight> = Highlight.fetchRequest()
|
||||
highlightsFetchRequest.predicate = NSPredicate(
|
||||
|
|
@ -91,21 +92,10 @@ public extension DataService {
|
|||
|
||||
guard let highlights = try? persistentContainer.viewContext.fetch(highlightsFetchRequest) else { return nil }
|
||||
|
||||
let highlightsJSONString = highlights.map { InternalHighlight.make(from: $0) }.asJSONString
|
||||
|
||||
let fetchRequest: NSFetchRequest<Models.PersistedArticleContent> = PersistedArticleContent.fetchRequest()
|
||||
fetchRequest.predicate = NSPredicate(
|
||||
format: "slug = %@", slug
|
||||
return ArticleContent(
|
||||
htmlContent: htmlContent,
|
||||
highlightsJSONString: highlights.map { InternalHighlight.make(from: $0) }.asJSONString
|
||||
)
|
||||
|
||||
if let articleContent = (try? persistentContainer.viewContext.fetch(fetchRequest))?.first {
|
||||
return ArticleContent(
|
||||
htmlContent: articleContent.htmlContent ?? "",
|
||||
highlightsJSONString: highlightsJSONString
|
||||
)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func invalidateCachedPage(slug _: String?) {}
|
||||
|
|
|
|||
|
|
@ -76,31 +76,18 @@ public extension DataService {
|
|||
|
||||
extension DataService {
|
||||
func persistArticleContent(htmlContent: String, slug: String, highlights: [InternalHighlight]) {
|
||||
let fetchContentRequest: NSFetchRequest<Models.PersistedArticleContent> = PersistedArticleContent.fetchRequest()
|
||||
fetchContentRequest.predicate = NSPredicate(
|
||||
format: "slug == %@", slug
|
||||
)
|
||||
|
||||
if let content = (try? persistentContainer.viewContext.fetch(fetchContentRequest))?.first {
|
||||
content.htmlContent = htmlContent
|
||||
} else {
|
||||
let persistedArticleContent = PersistedArticleContent(
|
||||
entity: PersistedArticleContent.entity(),
|
||||
insertInto: persistentContainer.viewContext
|
||||
)
|
||||
persistedArticleContent.htmlContent = htmlContent
|
||||
persistedArticleContent.slug = slug
|
||||
}
|
||||
|
||||
let fetchRequest: NSFetchRequest<Models.LinkedItem> = LinkedItem.fetchRequest()
|
||||
fetchRequest.predicate = NSPredicate(
|
||||
format: "slug == %@", slug
|
||||
)
|
||||
|
||||
if let linkedItemID = try? persistentContainer.viewContext.fetch(fetchRequest).first?.id {
|
||||
let linkedItem = try? persistentContainer.viewContext.fetch(fetchRequest).first
|
||||
|
||||
if let linkedItem = linkedItem, let linkedItemID = linkedItem.id {
|
||||
_ = highlights.map {
|
||||
$0.asManagedObject(context: persistentContainer.viewContext, associatedItemID: linkedItemID)
|
||||
}
|
||||
linkedItem.htmlContent = htmlContent
|
||||
}
|
||||
|
||||
do {
|
||||
|
|
|
|||
Loading…
Reference in a new issue