Fix messages failing to serialize and send with MongoDB ObjectId (BSON object)
Fix messages failing to serialize and send with MongoDB ObjectId (BSON object)
Closes https://gitlab.com/gitlab-org/gitter/webapp/issues/1898
Faye.copyObject
implementation
Finding differences in Setup:
# Run in the `gitter/faye` repo directory
$ npm link
# Run in the webapp repo directory
$ npm link gitter-faye
$ npm start -- --inspect-node
javascript/faye.js
var _ = require('lodash');
var dumpKeysRecursively = require('recursive-keys').dumpKeysRecursively;
var Faye = {
// ...
copyObject: function(object) {
var newResult = JSON.parse(JSON.stringify(object));
var oldResult = Faye.copyObjectLegacy(object);
var newKeys = dumpKeysRecursively(newResult).sort();
var oldKeys = dumpKeysRecursively(oldResult).sort();
if (!_.isEqual(oldKeys, newKeys)) {
//console.warn('Faye.copyObject different result (old, new)\n', oldResult, '\n', newResult);
let difference = oldKeys
.filter(x => {
var oldValue = _.get(oldResult, x);
return (oldValue !== undefined && typeof oldValue !== 'function') && !newKeys.includes(x);
})
.concat(newKeys.filter(x => {
var oldValue = _.get(oldResult, x);
return (oldValue !== undefined && typeof oldValue !== 'function') && !oldKeys.includes(x);
}));
if(difference && difference.length > 0) {
debugger;
}
}
return newResult;
},
copyObjectLegacy: function(object) {
var clone, i, key;
if (object instanceof Array) {
clone = [];
i = object.length;
while (i--) clone[i] = Faye.copyObjectLegacy(object[i]);
return clone;
} else if (typeof object === 'object') {
clone = (object === null) ? null : {};
for (key in object) clone[key] = Faye.copyObjectLegacy(object[key]);
return clone;
} else {
return object;
}
},
};
Edited by Eric Eastwood