Bug 1318669 - Remove stripPrivateProps from blocklist-clients.js, r?mgoodwin
MozReview-Commit-ID: 84yvzpBr3Q6
--- a/services/common/blocklist-clients.js
+++ b/services/common/blocklist-clients.js
@@ -36,31 +36,20 @@ const PREF_BLOCKLIST_GFX_CHECKED_SECONDS
const PREF_BLOCKLIST_ENFORCE_SIGNING = "services.blocklist.signing.enforced";
const INVALID_SIGNATURE = "Invalid content/signature";
this.FILENAME_ADDONS_JSON = "blocklist-addons.json";
this.FILENAME_GFX_JSON = "blocklist-gfx.json";
this.FILENAME_PLUGINS_JSON = "blocklist-plugins.json";
-function mergeChanges(localRecords, changes) {
- // Kinto.js adds attributes to local records that aren't present on server.
- // (e.g. _status)
- const stripPrivateProps = (obj) => {
- return Object.keys(obj).reduce((current, key) => {
- if (!key.startsWith("_")) {
- current[key] = obj[key];
- }
- return current;
- }, {});
- };
-
+function mergeChanges(collection, localRecords, changes) {
const records = {};
// Local records by id.
- localRecords.forEach((record) => records[record.id] = stripPrivateProps(record));
+ localRecords.forEach((record) => records[record.id] = collection.cleanLocalFields(record));
// All existing records are replaced by the version from the server.
changes.forEach((record) => records[record.id] = record);
return Object.values(records)
// Filter out deleted records.
.filter((record) => record.deleted != true)
// Sort list by record id.
.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
@@ -126,17 +115,17 @@ class BlocklistClient {
let toSerialize;
if (ignoreLocal) {
toSerialize = {
last_modified: `${payload.last_modified}`,
data: payload.data
};
} else {
const localRecords = (yield collection.list()).data;
- const records = mergeChanges(localRecords, payload.changes);
+ const records = mergeChanges(collection, localRecords, payload.changes);
toSerialize = {
last_modified: `${payload.lastModified}`,
data: records
};
}
const serialized = CanonicalJSON.stringify(toSerialize);