summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWu Cheng-Han2016-07-30 11:24:20 +0800
committerWu Cheng-Han2016-07-30 11:24:20 +0800
commitd5549c6a8443ee1ca38fe8136465ac9377a2c8f9 (patch)
treeb93180657f74007f284bb3caad386146730c00bc /lib
parent2f117a22cd21fa4fb67a3b2d687485795f86d030 (diff)
Add support of saving authorship to revision
Diffstat (limited to 'lib')
-rw-r--r--lib/models/revision.js13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/models/revision.js b/lib/models/revision.js
index f525ea55..5d66f9fe 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({