diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/DeleteHighlight.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/DeleteHighlight.swift index 3050cc471..92f657946 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/DeleteHighlight.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/DeleteHighlight.swift @@ -50,11 +50,16 @@ public extension DataService { send(mutation, to: path, headers: headers) { result in let data = try? result.get() - let syncStatus: ServerSyncStatus = data == nil ? .needsDeletion : .isNSync + let isSyncSuccess = data != nil context.perform { guard let highlight = context.object(with: objectID) as? Highlight else { return } - highlight.serverSyncStatus = Int64(syncStatus.rawValue) + + if isSyncSuccess { + highlight.remove(inContext: context) + } else { + highlight.serverSyncStatus = Int64(ServerSyncStatus.needsDeletion.rawValue) + } do { try context.save() diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/RemoveLink.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/RemoveLink.swift index a4fa75fe4..304b00449 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/RemoveLink.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/RemoveLink.swift @@ -16,7 +16,7 @@ extension DataService { } } - func syncLinkDeletion(itemID: String, objectID _: NSManagedObjectID) { + func syncLinkDeletion(itemID: String, objectID: NSManagedObjectID) { enum MutationResult { case success(linkId: String) case error(errorCode: Enums.SetBookmarkArticleErrorCode) @@ -51,12 +51,16 @@ extension DataService { send(mutation, to: path, headers: headers) { result in let data = try? result.get() - let syncStatus: ServerSyncStatus = data == nil ? .needsDeletion : .isNSync + let isSyncSuccess = data != nil context.perform { - guard let linkedItem = LinkedItem.lookup(byID: itemID, inContext: context) else { return } - linkedItem.serverSyncStatus = Int64(syncStatus.rawValue) - // TODO: remove object if network req was sucessful + guard let linkedItem = context.object(with: objectID) as? LinkedItem else { return } + + if isSyncSuccess { + linkedItem.remove(inContext: context) + } else { + linkedItem.serverSyncStatus = Int64(ServerSyncStatus.needsDeletion.rawValue) + } do { try context.save()