Permalink
Browse files

if any recently-created notes are deleted before they can be given me…

…tadata, ensure they are queued to be deleted in situations where it's known that they will soon receive metadata; those queued deleted notes will rely on their created-counterparts (via "originalNote") to find the sync metadata
  • Loading branch information...
1 parent 972e86d commit 644db29dadfe527bcab9469f3857b2951ceb5577 Zachary Schneirov committed Feb 6, 2010
Showing with 32 additions and 6 deletions.
  1. +4 −0 DeletedNoteObject.h
  2. +8 −1 DeletedNoteObject.m
  3. +8 −1 SimplenoteEntryCollector.m
  4. +12 −4 SimplenoteSession.m
View
@@ -16,10 +16,14 @@
unsigned int logSequenceNumber;
CFUUIDBytes uniqueNoteIDBytes;
NSMutableDictionary *syncServicesMD;
+ id <SynchronizedNote> originalNote;
}
+ (id)deletedNoteWithNote:(id <SynchronizedNote>)aNote;
- (id)initWithExistingObject:(id<SynchronizedNote>)note;
+
+- (id<SynchronizedNote>)originalNote;
+
- (CFUUIDBytes *)uniqueNoteIDBytes;
- (NSDictionary *)syncServicesMD;
- (unsigned int)logSequenceNumber;
View
@@ -19,7 +19,9 @@ - (id)initWithExistingObject:(id<SynchronizedNote>)note {
CFUUIDBytes *bytes = [note uniqueNoteIDBytes];
uniqueNoteIDBytes = *bytes;
syncServicesMD = [[note syncServicesMD] mutableCopy];
- logSequenceNumber = [note logSequenceNumber];
+ logSequenceNumber = [note logSequenceNumber];
+ //not serialized: for runtime lookup purposes only
+ originalNote = [note retain];
}
return self;
}
@@ -55,6 +57,10 @@ - (void)encodeWithCoder:(NSCoder *)coder {
}
}
+- (id<SynchronizedNote>)originalNote {
+ return originalNote;
+}
+
- (NSString*)description {
return [NSString stringWithFormat:@"DeletedNoteObj %@", syncServicesMD];
}
@@ -63,6 +69,7 @@ - (NSString*)description {
- (void)dealloc {
[syncServicesMD release];
+ [originalNote release];
[super dealloc];
}
@@ -238,7 +238,14 @@ - (SyncResponseFetcher*)fetcherForDeletingNote:(DeletedNoteObject*)aDeletedNote
NSDictionary *info = [[aDeletedNote syncServicesMD] objectForKey:SimplenoteServiceName];
- NSAssert([info objectForKey:@"key"], @"fetcherForDeletingNote: got deleted note without a key?");
+ if (![info objectForKey:@"key"]) {
+ //the deleted note lacks a key, so look up its created-equivalent and use _its_ metadata
+ //handles the case of deleting a newly-created note after it had begun to sync, but before the remote operation gave it a key
+ //because notes are queued against each other, by the time the create operation finishes on originalNote, it will have syncMD
+ if ((info = [[[aDeletedNote originalNote] syncServicesMD] objectForKey:SimplenoteServiceName]))
+ [aDeletedNote setSyncObjectAndKeyMD:info forService:SimplenoteServiceName];
+ }
+ NSAssert([info objectForKey:@"key"], @"fetcherForDeletingNote: got deleted note and couldn't find a key anywhere!");
NSURL *noteURL = [SimplenoteSession servletURLWithPath:@"/api/delete" parameters:
[NSDictionary dictionaryWithObjectsAndKeys: email, @"email",
View
@@ -331,10 +331,18 @@ - (BOOL)pushSyncServiceChanges {
[notesToCreate addObject:aNote];
} else {
//in this case we probably intended to delete a note that didn't yet have metadata
- //in which case the deleted note would have already taken the created one's place, and there's nothing more we need to do
- NSLog(@"not creating an already-deleted note %@", aNote);
- //this presents a case in which we might have been waiting for unsynced notes to finish, but will now wait forever
- //thus this method indicates in the return value whether any notes were actually pushed
+ //in which case the deleted note would have already taken the created one's place, and there'd be nothing more we'd need to do --
+ //UNLESS it was just queued for creation and is -about- to get metadata
+ if ([notesBeingModified containsObject:aNote] ||
+ [[[(DeletedNoteObject*)aNote originalNote] syncServicesMD] objectForKey:SimplenoteServiceName]) {
+ //deleted notes w/o metadata should never be sent without a predecessor note already in progress
+ //so add aNote with the expectation that _modifyNotes will queue it; when this note is ready its originalNote will have syncMD
+ //alternatively, its originalNote might have been given metadata by now, in which case we should also add it
+ [notesToDelete addObject:aNote];
+ } else {
+ NSLog(@"not creating an already-deleted, not-being-modified-or-been-modified note %@", aNote);
+ [unsyncedServiceNotes removeObject:aNote];
+ }
}
}
}

0 comments on commit 644db29

Please sign in to comment.