@@ -13,7 +13,7 @@ import SwiftMessages
1313import os
1414
1515typealias SyncCompletionBlock = ( ) -> Void
16- typealias SyncCompletionBlockWithNote = ( _ note: CDNote ? ) -> Void
16+ typealias SyncCompletionBlockWithNote = ( _ note: Note ? ) -> Void
1717
1818struct ErrorMessage {
1919 var title : String
@@ -97,12 +97,12 @@ class NoteSessionManager {
9797 var message : ErrorMessage
9898 }
9999
100- enum Result < CDNote , NoteError> {
101- case success( CDNote ? )
100+ enum Result < Note , NoteError> {
101+ case success( Note ? )
102102 case failure( NoteError )
103103 }
104104
105- typealias SyncHandler = ( Result < CDNote , NoteError > ) -> Void
105+ typealias SyncHandler = ( Result < Note , NoteError > ) -> Void
106106
107107 static let shared = NoteSessionManager ( )
108108
@@ -275,7 +275,7 @@ class NoteSessionManager {
275275 logger. notice ( " Synchronizing... " )
276276
277277 func deleteOnServer( completion: @escaping SyncCompletionBlock ) {
278- if let notesToDelete = CDNote . notes ( property: " cdDeleteNeeded " ) ,
278+ if let notesToDelete = Note . notes ( property: " deleteNeeded " ) ,
279279 !notesToDelete. isEmpty {
280280 let group = DispatchGroup ( )
281281
@@ -296,7 +296,7 @@ class NoteSessionManager {
296296 }
297297
298298 func addOnServer( completion: @escaping SyncCompletionBlock ) {
299- if let notesToAdd = CDNote . notes ( property: " cdAddNeeded " ) ,
299+ if let notesToAdd = Note . notes ( property: " addNeeded " ) ,
300300 !notesToAdd. isEmpty {
301301 let group = DispatchGroup ( )
302302
@@ -322,7 +322,7 @@ class NoteSessionManager {
322322 }
323323
324324 func updateOnServer( completion: @escaping SyncCompletionBlock ) {
325- if let notesToUpdate = CDNote . notes ( property: " cdUpdateNeeded " ) ,
325+ if let notesToUpdate = Note . notes ( property: " updateNeeded " ) ,
326326 !notesToUpdate. isEmpty {
327327 let group = DispatchGroup ( )
328328
@@ -369,10 +369,10 @@ class NoteSessionManager {
369369 if let jsonArray = json as? Array < [ String : Any ] > {
370370 print ( jsonArray)
371371 if let serverIds = jsonArray. map ( { $0 [ " id " ] } ) as? [ Int64 ] ,
372- let knownIds = CDNote . all ( ) ? . map ( { $0. id } ) . filter ( { $0 > 0 } ) {
372+ let knownIds = Note . all ( ) ? . map ( { $0. id } ) . filter ( { $0 > 0 } ) {
373373 let deletedOnServer = Set ( knownIds) . subtracting ( Set ( serverIds) )
374374 if !deletedOnServer. isEmpty {
375- CDNote . delete ( ids: Array ( deletedOnServer) )
375+ Note . delete ( ids: Array ( deletedOnServer) )
376376 }
377377 }
378378 let filteredDicts = jsonArray. filter ( { $0. keys. count > 1 } )
@@ -381,7 +381,7 @@ class NoteSessionManager {
381381 for noteDict in filteredDicts {
382382 notes. append ( NoteStruct ( dictionary: noteDict) )
383383 }
384- CDNote . update ( notes: notes)
384+ Note . update ( notes: notes)
385385 }
386386 }
387387 case let . failure( error) :
@@ -427,12 +427,12 @@ class NoteSessionManager {
427427 logger. notice ( " Adding note... " )
428428
429429 let note = NoteStruct ( content: content, category: category, favorite: favorite ?? false )
430- if let incoming = CDNote . update ( note: note) { //addNeeded defaults to true
430+ if let incoming = Note . update ( note: note) { //addNeeded defaults to true
431431 self . add ( note: incoming, completion: completion)
432432 }
433433 }
434434
435- func add( note: CDNote , completion: SyncCompletionBlockWithNote ? = nil ) {
435+ func add( note: Note , completion: SyncCompletionBlockWithNote ? = nil ) {
436436 if NoteSessionManager . isOnline {
437437 addToServer ( note: note) { [ weak self] result in
438438 switch result {
@@ -450,9 +450,9 @@ class NoteSessionManager {
450450 }
451451 }
452452
453- func addToServer( note: CDNote , handler: @escaping SyncHandler ) {
453+ func addToServer( note: Note , handler: @escaping SyncHandler ) {
454454 let newNote = note
455- var result : CDNote ?
455+ var result : Note ?
456456 let parameters : Parameters = [ " title " : note. title as Any ,
457457 " content " : note. content as Any ,
458458 " category " : note. category as Any ,
@@ -479,7 +479,7 @@ class NoteSessionManager {
479479 newNote. category = note. category
480480 newNote. addNeeded = false
481481 newNote. updateNeeded = false
482- result = CDNote . update ( note: newNote)
482+ result = Note . update ( note: newNote)
483483 handler ( . success( result) )
484484 case let . failure( error) :
485485 let message = ErrorMessage ( title: NSLocalizedString ( " Error Adding Note " , comment: " The title of an error message " ) ,
@@ -505,7 +505,7 @@ class NoteSessionManager {
505505 . responseDecodable ( of: NoteStruct . self) { response in
506506 switch response. result {
507507 case let . success( note) :
508- CDNote . update ( notes: [ note] )
508+ Note . update ( notes: [ note] )
509509 case let . failure( error) :
510510 if let urlResponse = response. response {
511511 switch urlResponse. statusCode {
@@ -516,7 +516,7 @@ class NoteSessionManager {
516516 print ( error)
517517 case 404 :
518518 if let guid = note. guid,
519- let dbNote = CDNote . note ( guid: guid) {
519+ let dbNote = Note . note ( guid: guid) {
520520 self . add ( note: dbNote, completion: nil )
521521 }
522522 default :
@@ -548,7 +548,7 @@ class NoteSessionManager {
548548 }
549549 }
550550 } else {
551- CDNote . update ( notes: [ incoming] )
551+ Note . update ( notes: [ incoming] )
552552 completion ? ( )
553553 }
554554 }
@@ -567,17 +567,17 @@ class NoteSessionManager {
567567 . responseDecodable ( of: NoteStruct . self) { response in
568568 switch response. result {
569569 case let . success( note) :
570- CDNote . update ( notes: [ note] )
570+ Note . update ( notes: [ note] )
571571 handler ( . success( nil ) )
572572 case let . failure( error) :
573- CDNote . update ( notes: [ note] )
573+ Note . update ( notes: [ note] )
574574 let message = ErrorMessage ( title: NSLocalizedString ( " Error Updating Note " , comment: " The title of an error message " ) ,
575575 body: error. localizedDescription)
576576 if let urlResponse = response. response {
577577 switch urlResponse. statusCode {
578578 case 404 , 405 :
579579 if let guid = note. guid,
580- let dbNote = CDNote . note ( guid: guid) {
580+ let dbNote = Note . note ( guid: guid) {
581581 self . add ( note: dbNote, completion: nil )
582582 }
583583 handler ( . success( nil ) )
@@ -597,7 +597,7 @@ class NoteSessionManager {
597597 var incoming = note
598598 incoming. deleteNeeded = true
599599 if incoming. addNeeded {
600- CDNote . delete ( note: incoming)
600+ Note . delete ( note: incoming)
601601 completion ? ( )
602602 } else if NoteSessionManager . isOnline {
603603 deleteOnServer ( incoming) { [ weak self] result in
@@ -612,7 +612,7 @@ class NoteSessionManager {
612612 }
613613 }
614614 } else {
615- CDNote . update ( notes: [ incoming] )
615+ Note . update ( notes: [ incoming] )
616616 completion ? ( )
617617 }
618618 }
@@ -625,7 +625,7 @@ class NoteSessionManager {
625625 . responseData { ( response) in
626626 switch response. result {
627627 case . success:
628- CDNote . delete ( note: note)
628+ Note . delete ( note: note)
629629 handler ( . success( nil ) )
630630 case . failure( let error) :
631631 var message = ErrorMessage ( title: NSLocalizedString ( " Error Deleting Note " , comment: " The title of an error message " ) ,
@@ -635,14 +635,14 @@ class NoteSessionManager {
635635 case 404 :
636636 //Note doesn't exist on the server but we are obviously
637637 //trying to delete it, so let's do that.
638- CDNote . delete ( note: note)
638+ Note . delete ( note: note)
639639 handler ( . success( nil ) )
640640 case 423 :
641641 message. body = NSLocalizedString ( " Unable to delete locked file on server " , comment: " " )
642- CDNote . delete ( note: note)
642+ Note . delete ( note: note)
643643 handler ( . failure( NoteError ( message: message) ) )
644644 default :
645- CDNote . update ( notes: [ note] )
645+ Note . update ( notes: [ note] )
646646 handler ( . failure( NoteError ( message: message) ) )
647647 }
648648 }
0 commit comments