Add support of saving authorship to revision
This commit is contained in:
parent
2f117a22cd
commit
d5549c6a84
1 changed files with 10 additions and 3 deletions
|
@ -100,6 +100,7 @@ module.exports = function (sequelize, DataTypes) {
|
||||||
var startContent = null;
|
var startContent = null;
|
||||||
var lastPatch = [];
|
var lastPatch = [];
|
||||||
var applyPatches = [];
|
var applyPatches = [];
|
||||||
|
var authorship = [];
|
||||||
if (count <= Math.round(revisions.length / 2)) {
|
if (count <= Math.round(revisions.length / 2)) {
|
||||||
// start from top to target
|
// start from top to target
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
|
@ -112,6 +113,7 @@ module.exports = function (sequelize, DataTypes) {
|
||||||
applyPatches = applyPatches.concat(patch);
|
applyPatches = applyPatches.concat(patch);
|
||||||
}
|
}
|
||||||
lastPatch = revision.patch;
|
lastPatch = revision.patch;
|
||||||
|
authorship = revision.authorship;
|
||||||
}
|
}
|
||||||
// swap DIFF_INSERT and DIFF_DELETE to achieve unpatching
|
// swap DIFF_INSERT and DIFF_DELETE to achieve unpatching
|
||||||
for (var i = 0, l = applyPatches.length; i < l; i++) {
|
for (var i = 0, l = applyPatches.length; i < l; i++) {
|
||||||
|
@ -130,12 +132,14 @@ module.exports = function (sequelize, DataTypes) {
|
||||||
var revision = revisions[i];
|
var revision = revisions[i];
|
||||||
if (i == l) {
|
if (i == l) {
|
||||||
startContent = LZString.decompressFromBase64(revision.lastContent);
|
startContent = LZString.decompressFromBase64(revision.lastContent);
|
||||||
|
authorship = revision.authorship;
|
||||||
}
|
}
|
||||||
if (revision.patch) {
|
if (revision.patch) {
|
||||||
var patch = dmp.patch_fromText(LZString.decompressFromBase64(revision.patch));
|
var patch = dmp.patch_fromText(LZString.decompressFromBase64(revision.patch));
|
||||||
applyPatches = applyPatches.concat(patch);
|
applyPatches = applyPatches.concat(patch);
|
||||||
}
|
}
|
||||||
lastPatch = revision.patch;
|
lastPatch = revision.patch;
|
||||||
|
authorship = revision.authorship;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -145,7 +149,8 @@ module.exports = function (sequelize, DataTypes) {
|
||||||
}
|
}
|
||||||
var data = {
|
var data = {
|
||||||
content: finalContent,
|
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();
|
var ms_end = (new Date()).getTime();
|
||||||
if (config.debug) {
|
if (config.debug) {
|
||||||
|
@ -218,7 +223,8 @@ module.exports = function (sequelize, DataTypes) {
|
||||||
Revision.create({
|
Revision.create({
|
||||||
noteId: note.id,
|
noteId: note.id,
|
||||||
lastContent: note.content,
|
lastContent: note.content,
|
||||||
length: LZString.decompressFromBase64(note.content).length
|
length: LZString.decompressFromBase64(note.content).length,
|
||||||
|
authorship: note.authorship
|
||||||
}).then(function (revision) {
|
}).then(function (revision) {
|
||||||
Revision.finishSaveNoteRevision(note, revision, callback);
|
Revision.finishSaveNoteRevision(note, revision, callback);
|
||||||
}).catch(function (err) {
|
}).catch(function (err) {
|
||||||
|
@ -244,7 +250,8 @@ module.exports = function (sequelize, DataTypes) {
|
||||||
noteId: note.id,
|
noteId: note.id,
|
||||||
patch: LZString.compressToBase64(patch),
|
patch: LZString.compressToBase64(patch),
|
||||||
content: note.content,
|
content: note.content,
|
||||||
length: LZString.decompressFromBase64(note.content).length
|
length: LZString.decompressFromBase64(note.content).length,
|
||||||
|
authorship: note.authorship
|
||||||
}).then(function (revision) {
|
}).then(function (revision) {
|
||||||
// clear last revision content to reduce db size
|
// clear last revision content to reduce db size
|
||||||
latestRevision.update({
|
latestRevision.update({
|
||||||
|
|
Loading…
Reference in a new issue