diff --git a/app/assets/javascripts/app/models/api/item.js b/app/assets/javascripts/app/models/api/item.js index 1c3dcff1d..d2f77577d 100644 --- a/app/assets/javascripts/app/models/api/item.js +++ b/app/assets/javascripts/app/models/api/item.js @@ -185,7 +185,27 @@ class Item { return this.getAppDataItem("archived"); } + /* + During sync conflicts, when determing whether to create a duplicate for an item, we can omit keys that have no + meaningful weight and can be ignored. For example, if one component has active = true and another component has active = false, + it would be silly to duplicate them, so instead we ignore this. + */ + keysToIgnoreWhenCheckingContentEquality() { + return []; + } + isItemContentEqualWith(otherItem) { + let omit = (obj, keys) => { + for(var key of keys) { + delete obj[key]; + } + return obj; + } + var left = omit(this.structureParams(), this.keysToIgnoreWhenCheckingContentEquality()); + var right = omit(otherItem.structureParams(), otherItem.keysToIgnoreWhenCheckingContentEquality()); + + return JSON.stringify(left) === JSON.stringify(right) + } /* Dates diff --git a/app/assets/javascripts/app/models/app/component.js b/app/assets/javascripts/app/models/app/component.js index 84f2efacf..a94ff9748 100644 --- a/app/assets/javascripts/app/models/app/component.js +++ b/app/assets/javascripts/app/models/app/component.js @@ -96,6 +96,10 @@ class Component extends Item { return this.getAppDataItem("lastSize"); } + keysToIgnoreWhenCheckingContentEquality() { + return ["active"].concat(super.keysToIgnoreWhenCheckingContentEquality()); + } + /* An associative component depends on being explicitly activated for a given item, compared to a dissaciative component, diff --git a/app/assets/javascripts/app/services/syncManager.js b/app/assets/javascripts/app/services/syncManager.js index bf80cd75b..dfb8dc12b 100644 --- a/app/assets/javascripts/app/services/syncManager.js +++ b/app/assets/javascripts/app/services/syncManager.js @@ -434,7 +434,7 @@ class SyncManager { itemResponse.uuid = null; var dup = this.modelManager.createDuplicateItem(itemResponse, item); - if(!itemResponse.deleted && JSON.stringify(item.structureParams()) !== JSON.stringify(dup.structureParams())) { + if(!itemResponse.deleted && !item.isItemContentEqualWith(dup)) { this.modelManager.addItem(dup); dup.conflict_of = item.uuid; dup.setDirty(true);