Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions ContentstackPersistence/SyncManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,34 @@ -(NSString*) getSyncToken {
return syncToken;
}

-(NSString*) getSeqId {
__block NSString *seqId;
[self.persistanceDelegate performBlockAndWait:^{
id<SyncStoreProtocol> syncStack = [self findOrCreate:self->_syncStack predicate:nil];
seqId = syncStack.seqId;
}];
return seqId;
}

-(void)updateSyncStack:(SyncStack*)syncStack {
id<SyncStoreProtocol> syncStore = (id<SyncStoreProtocol>)[self findOrCreate:_syncStack predicate:nil];
syncStore.syncToken = syncStack.syncToken;
syncStore.paginationToken = syncStack.paginationToken;
syncStore.seqId = syncStack.seqId;
}

-(void)syncWithInit:(BOOL) shouldInit onCompletion:(void (^)(double, BOOL, NSError * _Nullable))completion {
NSString *paginationToken = [self getPaginationToken];//csb0e8704474a9624785098d233edd2715`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented tokens should be removed

NSString *syncToken = [self getSyncToken];//cse053899d15e9e94cd3751df26f719c87
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented tokens should be removed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ishaileshmishra , yes they are removed.

NSString *seqId = [self getSeqId];
NSString *syncToken = [self getSyncToken];
NSString *paginationToken = [self getPaginationToken];
__weak typeof (self) weakSelf = self;
id completionBlock = ^(SyncStack * _Nullable syncStack, NSError * _Nullable error) {
if (error != nil) {
//Init the sync API on pagination and sync token errors
if (error.code == 422) {
if (error.userInfo && error.userInfo[@"errors"]) {
NSDictionary *errors = error.userInfo[@"errors"];
if (errors[@"pagination_token"] || errors[@"sync_token"]) {
if (errors[@"pagination_token"] || errors[@"sync_token"] || errors[@"seq_id"]) {
[weakSelf syncWithInit:true onCompletion:completion];
return;
}
Expand Down Expand Up @@ -141,8 +152,7 @@ -(void)syncWithInit:(BOOL) shouldInit onCompletion:(void (^)(double, BOOL, NSErr
NSArray *publishEntryArray = [syncStack.items filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"type = 'entry_published'"]];
[self createEntries:publishEntryArray];

//Sync toke Update
if (syncStack.syncToken != nil) {
if (syncStack.items.count == 0) {
isSyncCompleted = true;
[self updateSyncStack:syncStack];
}
Expand All @@ -158,11 +168,13 @@ -(void)syncWithInit:(BOOL) shouldInit onCompletion:(void (^)(double, BOOL, NSErr
if (shouldInit) {
self.percentageComplete = 0;
[_stack sync:completionBlock];
}else if (paginationToken != nil) {
} else if (seqId != nil) {
[_stack syncSeqId:seqId completion:completionBlock];
} else if (paginationToken != nil) {
[_stack syncPaginationToken:paginationToken completion:completionBlock];
}else if (syncToken != nil) {
} else if (syncToken != nil) {
[_stack syncToken:syncToken completion:completionBlock];
}else {
} else {
self.percentageComplete = 0;
[_stack sync:completionBlock];
}
Expand Down
1 change: 1 addition & 0 deletions ContentstackPersistence/SyncProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@required
@property (nonatomic)NSString* paginationToken;
@property (nonatomic)NSString* syncToken;
@property (nonatomic)NSString* seqId;
@end

/**
Expand Down