Model manager and sync updates

This commit is contained in:
Mo Bitar
2017-09-27 13:16:00 -05:00
parent 407a235a15
commit 63f75491a8
4 changed files with 13 additions and 7 deletions

View File

@@ -165,8 +165,6 @@ class ModelManager {
}
addItems(items) {
this.items = _.uniq(this.items.concat(items));
items.forEach(function(item){
if(item.content_type == "Tag") {
if(!_.find(this.tags, {uuid: item.uuid})) {
@@ -184,6 +182,10 @@ class ModelManager {
this._extensions.unshift(item);
}
}
if(!_.find(this.items, {uuid: item.uuid})) {
this.items.push(item);
}
}.bind(this));
}
@@ -203,7 +205,7 @@ class ModelManager {
// If another client removes an item's references, this client won't pick up the removal unless
// we remove everything not present in the current list of references
item.removeReferencesNotPresentIn(contentObject.references);
item.removeReferencesNotPresentIn(contentObject.references || []);
if(!contentObject.references) {
return;

View File

@@ -24,8 +24,9 @@ class SyncManager {
}
writeItemsToLocalStorage(items, offlineOnly, callback) {
var version = this.authManager.protocolVersion();
var params = items.map(function(item) {
var itemParams = new ItemParams(item, null, this.authManager.protocolVersion());
var itemParams = new ItemParams(item, null, version);
itemParams = itemParams.paramsForLocalStorage();
if(offlineOnly) {
delete itemParams.dirty;
@@ -194,10 +195,13 @@ class SyncManager {
this.allRetreivedItems = [];
}
var version = this.authManager.protocolVersion();
var keys = this.authManager.keys();
var params = {};
params.limit = 150;
params.items = _.map(subItems, function(item){
var itemParams = new ItemParams(item, this.authManager.keys(), this.authManager.protocolVersion());
var itemParams = new ItemParams(item, keys, version);
itemParams.additionalFields = options.additionalFields;
return itemParams.paramsForSync();
}.bind(this));