mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
delete linkedItem and highlight when server sync suceeeds
This commit is contained in:
parent
c9052f5f81
commit
8433f3a226
2 changed files with 16 additions and 7 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue