Skip to content

Commit

Permalink
Tag sync fixes. Notes are now given the opportunity to update/upgrade…
Browse files Browse the repository at this point in the history
… metadata/tags with info returned by the list even when content versions are considered the same.
  • Loading branch information
darrylhthomas authored and ttscoff committed May 20, 2011
1 parent c072074 commit 8725f27
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NotationSyncServiceManager.m
Expand Up @@ -159,6 +159,10 @@ - (void)makeNotesMatchList:(NSArray*)MDEntries fromSyncSession:(id <SyncServiceS
[locallyChangedNotes addObject:note];
} else if (changeDiff == NSOrderedAscending) {
[remotelyChangedNotes addObject:note];
} else {
//if the note is considered unchanged, still give the sync service an
//opportunity to update metadata/tags with info returned by the list
[syncSession applyMetadataUpdatesToNote:note localEntry:thisServiceInfo remoteEntry:remoteInfo];
}
} else if (changeDiff != NSOrderedDescending) {
//nah ah ah, a delete should not stick if local mod time is newer! otherwise local changes will be lost
Expand Down
1 change: 1 addition & 0 deletions SimplenoteSession.h
Expand Up @@ -74,6 +74,7 @@ extern NSString *SimplenoteSeparatorKey;
- (BOOL)reachabilityFailed;

- (NSComparisonResult)localEntry:(NSDictionary*)localEntry compareToRemoteEntry:(NSDictionary*)remoteEntry;
-(void)applyMetadataUpdatesToNote:(id <SynchronizedNote>)aNote localEntry:(NSDictionary *)localEntry remoteEntry: (NSDictionary *)remoteEntry;
- (BOOL)remoteEntryWasMarkedDeleted:(NSDictionary*)remoteEntry;
- (BOOL)entryHasLocalChanges:(NSDictionary*)entry;
- (BOOL)tagsShouldBeMergedForEntry:(NSDictionary*)entry;
Expand Down
41 changes: 40 additions & 1 deletion SimplenoteSession.m
Expand Up @@ -165,6 +165,35 @@ - (NSComparisonResult)localEntry:(NSDictionary*)localEntry compareToRemoteEntry:
return NSOrderedSame;
}

-(void)applyMetadataUpdatesToNote:(id <SynchronizedNote>)aNote localEntry:(NSDictionary *)localEntry remoteEntry: (NSDictionary *)remoteEntry {
//tags may have updated even if content wasn't, or we may never have synced tags
NSSet *localTagset = [NSSet setWithArray:[(NoteObject *)aNote orderedLabelTitles]];
NSSet *remoteTagset = [NSSet setWithArray:[remoteEntry objectForKey:@"tags"]];
if (![localTagset isEqualToSet:remoteTagset]) {
NSLog(@"Tagsets differ. Updating.");
NSString *newLabelString = nil;
if ([self tagsShouldBeMergedForEntry:localEntry]) {
NSMutableSet *mergedTags = [NSMutableSet setWithSet:localTagset];
[mergedTags unionSet:remoteTagset];
if ([mergedTags count]) {
newLabelString = [[mergedTags allObjects] componentsJoinedByString:@" "];
}
} else {
if ([remoteTagset count]) {
newLabelString = [[remoteTagset allObjects] componentsJoinedByString:@" "];
}
}
[(NoteObject *)aNote setLabelString:newLabelString];
}

//set the metadata from the server if this is the first time syncing with api2
if (![localEntry objectForKey:@"syncnum"]) {
NSDictionary *updatedMetadata = [NSDictionary dictionaryWithObjectsAndKeys:[remoteEntry objectForKey:@"syncnum"], @"syncnum", [remoteEntry objectForKey:@"version"], @"version", [remoteEntry objectForKey:@"modify"], @"modify", nil];

[aNote setSyncObjectAndKeyMD: updatedMetadata forService: SimplenoteServiceName];
}
}

- (BOOL)remoteEntryWasMarkedDeleted:(NSDictionary*)remoteEntry {
return [[remoteEntry objectForKey:@"deleted"] intValue] == 1;
}
Expand Down Expand Up @@ -1005,14 +1034,24 @@ - (void)syncResponseFetcher:(SyncResponseFetcher*)fetcher receivedData:(NSData*)
NSString *noteKey = [rawEntry objectForKey:@"key"];
NSNumber *syncnum = [NSNumber numberWithInt:[[rawEntry objectForKey:@"syncnum"] intValue]];
NSNumber *modified = [NSNumber numberWithDouble:[[NSDate dateWithTimeIntervalSince1970:[[rawEntry objectForKey:@"modifydate"] doubleValue]] timeIntervalSinceReferenceDate]];
NSNumber *minversion = [NSNumber numberWithInt:[[rawEntry objectForKey:@"minversion"] intValue]];
NSNumber *version = [NSNumber numberWithInt:[[rawEntry objectForKey:@"version"] intValue]];
NSArray *tags = [rawEntry objectForKey:@"tags"];
NSArray *systemtags = [rawEntry objectForKey:@"systemtags"];

if ([noteKey length] && [syncnum intValue] && [modified doubleValue]) {
//convenient intermediate format
//convenient intermediate format, including all metadata included
//in the index, so we don't need to fetch the individual note if
//content hasn't changed
[entries addObject:[NSDictionary dictionaryWithObjectsAndKeys:
noteKey, @"key",
[NSNumber numberWithInt:[[rawEntry objectForKey:@"deleted"] intValue]], @"deleted",
modified, @"modify",
syncnum, @"syncnum",
minversion, @"minversion",
version, @"version",
systemtags, @"systemtags",
tags, @"tags",
nil]];
}
}
Expand Down
1 change: 1 addition & 0 deletions SyncServiceSessionProtocol.h
Expand Up @@ -32,6 +32,7 @@
- (id)initWithNotationPrefs:(NotationPrefs*)prefs;

- (NSComparisonResult)localEntry:(NSDictionary*)localEntry compareToRemoteEntry:(NSDictionary*)remoteEntry;
-(void)applyMetadataUpdatesToNote:(id <SynchronizedNote>)aNote localEntry:(NSDictionary *)localEntry remoteEntry: (NSDictionary *)remoteEntry;
- (BOOL)remoteEntryWasMarkedDeleted:(NSDictionary*)remoteEntry;
+ (void)registerLocalModificationForNote:(id <SynchronizedNote>)aNote;

Expand Down

0 comments on commit 8725f27

Please sign in to comment.