Skip to content

Commit

Permalink
Merging local diff with ghost data
Browse files Browse the repository at this point in the history
Merging local diff with ghost data incase there were some default
values on newly added objects that the remote is not aware of.
  • Loading branch information
lukman-foreflight committed Aug 2, 2017
1 parent 4565c54 commit fc973b1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Simperium/SPChangeProcessor.m
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,20 @@ - (BOOL)_processRemoteModifyWithKey:(NSString *)simperiumKey
NSDictionary *diff = change[CH_VALUE];
NSError *theError = nil;

NSDictionary *diffToApply = nil;

if (newlyAdded) {
NSMutableDictionary *currentDiff = [[bucket.differ diffFromDictionary:@{} toObject:object] mutableCopy];
if (currentDiff.count > 0) {
[currentDiff addEntriesFromDictionary:diff];
diffToApply = currentDiff;
}
}else{
diffToApply = diff;
}

// Apply the diff to the ghost and store the new data in the object's ghost
if (![bucket.differ applyGhostDiffFromDictionary:diff toObject:object error:&theError]) {
if (![bucket.differ applyGhostDiffFromDictionary:diffToApply toObject:object error:&theError]) {
SPLogError(@"Simperium error during applyGhostDiff: %@", theError.localizedDescription);
if (error) {
*error = [NSError sp_errorWithDomain:NSStringFromClass([self class]) code:SPProcessorErrorsReceivedInvalidChange description:theError.description];
Expand Down

0 comments on commit fc973b1

Please sign in to comment.