filter feeditems on needsDeletion server sync status
This commit is contained in:
@ -69,6 +69,9 @@ import Views
|
||||
dataService.viewContext.perform {
|
||||
let fetchRequest: NSFetchRequest<Models.LinkedItem> = LinkedItem.fetchRequest()
|
||||
fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \LinkedItem.savedAt, ascending: false)]
|
||||
fetchRequest.predicate = NSPredicate(
|
||||
format: "serverSyncStatus != %@", ServerSyncStatus.needsDeletion.rawValue
|
||||
)
|
||||
if let fetchedItems = try? dataService.viewContext.fetch(fetchRequest) {
|
||||
self?.items = fetchedItems
|
||||
self?.cursor = nil
|
||||
|
||||
@ -6,10 +6,10 @@
|
||||
<attribute name="createdByMe" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<attribute name="id" attributeType="String"/>
|
||||
<attribute name="markedForDeletion" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="needServerSynch" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="patch" attributeType="String"/>
|
||||
<attribute name="prefix" optional="YES" attributeType="String"/>
|
||||
<attribute name="quote" attributeType="String"/>
|
||||
<attribute name="serverSyncStatus" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="shortId" attributeType="String"/>
|
||||
<attribute name="suffix" optional="YES" attributeType="String"/>
|
||||
<attribute name="updatedAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
@ -29,7 +29,6 @@
|
||||
<attribute name="id" attributeType="String"/>
|
||||
<attribute name="imageURLString" optional="YES" attributeType="String"/>
|
||||
<attribute name="isArchived" attributeType="Boolean" usesScalarValueType="YES"/>
|
||||
<attribute name="needServerSynch" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="onDeviceImageURLString" optional="YES" attributeType="String"/>
|
||||
<attribute name="pageURLString" attributeType="String"/>
|
||||
<attribute name="publishDate" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
|
||||
@ -37,6 +36,7 @@
|
||||
<attribute name="readingProgress" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
|
||||
<attribute name="readingProgressAnchor" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="savedAt" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="serverSyncStatus" attributeType="Integer 64" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="slug" attributeType="String"/>
|
||||
<attribute name="title" attributeType="String"/>
|
||||
<relationship name="highlights" toMany="YES" deletionRule="Cascade" destinationEntity="Highlight" inverseName="linkedItem" inverseEntity="Highlight"/>
|
||||
@ -53,7 +53,7 @@
|
||||
<attribute name="id" attributeType="String"/>
|
||||
<attribute name="labelDescription" optional="YES" attributeType="String"/>
|
||||
<attribute name="name" attributeType="String"/>
|
||||
<attribute name="needServerSynch" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<attribute name="serverSyncStatus" attributeType="Integer 64" defaultValueString="NO" usesScalarValueType="YES"/>
|
||||
<uniquenessConstraints>
|
||||
<uniquenessConstraint>
|
||||
<constraint value="id"/>
|
||||
|
||||
@ -77,7 +77,8 @@ public extension LinkedItem {
|
||||
inContext context: NSManagedObjectContext,
|
||||
newReadingProgress: Double? = nil,
|
||||
newAnchorIndex: Int? = nil,
|
||||
newIsArchivedValue: Bool? = nil
|
||||
newIsArchivedValue: Bool? = nil,
|
||||
needsServerSync: Bool = false
|
||||
) {
|
||||
context.perform {
|
||||
if let newReadingProgress = newReadingProgress {
|
||||
@ -92,6 +93,10 @@ public extension LinkedItem {
|
||||
self.isArchived = newIsArchivedValue
|
||||
}
|
||||
|
||||
if needsServerSync {
|
||||
self.serverSyncStatus = Int64(ServerSyncStatus.needsUpdate.rawValue)
|
||||
}
|
||||
|
||||
guard context.hasChanges else { return }
|
||||
|
||||
do {
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
import Foundation
|
||||
|
||||
public enum ServerSyncStatus: Int {
|
||||
case isNSync
|
||||
case isSyncing
|
||||
case needsDeletion
|
||||
case needsCreation
|
||||
case needsUpdate
|
||||
}
|
||||
@ -72,8 +72,12 @@ public extension DataService {
|
||||
|
||||
guard let linkedItem = try? persistentContainer.viewContext.fetch(linkedItemFetchRequest).first else { return nil }
|
||||
guard let htmlContent = linkedItem.htmlContent else { return nil }
|
||||
let highlights = linkedItem.highlights.asArray(of: Highlight.self
|
||||
)
|
||||
|
||||
let highlights = linkedItem
|
||||
.highlights
|
||||
.asArray(of: Highlight.self)
|
||||
.filter { $0.serverSyncStatus != ServerSyncStatus.needsDeletion.rawValue }
|
||||
|
||||
return ArticleContent(
|
||||
htmlContent: htmlContent,
|
||||
highlightsJSONString: highlights.map { InternalHighlight.make(from: $0) }.asJSONString
|
||||
|
||||
Reference in New Issue
Block a user