diff --git a/lib/models/revision.js b/lib/models/revision.js index f525ea5..5d66f9f 100644 --- a/lib/models/revision.js +++ b/lib/models/revision.js @@ -100,6 +100,7 @@ module.exports = function (sequelize, DataTypes) { var startContent = null; var lastPatch = []; var applyPatches = []; + var authorship = []; if (count <= Math.round(revisions.length / 2)) { // start from top to target for (var i = 0; i < count; i++) { @@ -112,6 +113,7 @@ module.exports = function (sequelize, DataTypes) { applyPatches = applyPatches.concat(patch); } lastPatch = revision.patch; + authorship = revision.authorship; } // swap DIFF_INSERT and DIFF_DELETE to achieve unpatching for (var i = 0, l = applyPatches.length; i < l; i++) { @@ -130,12 +132,14 @@ module.exports = function (sequelize, DataTypes) { var revision = revisions[i]; if (i == l) { startContent = LZString.decompressFromBase64(revision.lastContent); + authorship = revision.authorship; } if (revision.patch) { var patch = dmp.patch_fromText(LZString.decompressFromBase64(revision.patch)); applyPatches = applyPatches.concat(patch); } lastPatch = revision.patch; + authorship = revision.authorship; } } try { @@ -145,7 +149,8 @@ module.exports = function (sequelize, DataTypes) { } var data = { content: finalContent, - patch: dmp.patch_fromText(LZString.decompressFromBase64(lastPatch)) + patch: dmp.patch_fromText(LZString.decompressFromBase64(lastPatch)), + authorship: authorship ? JSON.parse(LZString.decompressFromBase64(authorship)) : null }; var ms_end = (new Date()).getTime(); if (config.debug) { @@ -218,7 +223,8 @@ module.exports = function (sequelize, DataTypes) { Revision.create({ noteId: note.id, lastContent: note.content, - length: LZString.decompressFromBase64(note.content).length + length: LZString.decompressFromBase64(note.content).length, + authorship: note.authorship }).then(function (revision) { Revision.finishSaveNoteRevision(note, revision, callback); }).catch(function (err) { @@ -244,7 +250,8 @@ module.exports = function (sequelize, DataTypes) { noteId: note.id, patch: LZString.compressToBase64(patch), content: note.content, - length: LZString.decompressFromBase64(note.content).length + length: LZString.decompressFromBase64(note.content).length, + authorship: note.authorship }).then(function (revision) { // clear last revision content to reduce db size latestRevision.update({