This commit is contained in:
yflory
2020-04-09 16:06:04 +02:00
parent cba8f5fce6
commit 62fde59a89
4 changed files with 251 additions and 86 deletions

View File

@@ -48,7 +48,6 @@ define(['json.sortify'], function (Sortify) {
//title: meta.doc.defaultTitle,
type: meta.doc.type,
users: {},
authors: {}
};
metadataLazyObj = JSON.parse(JSON.stringify(metadataObj));
}
@@ -69,6 +68,10 @@ define(['json.sortify'], function (Sortify) {
}
metadataObj.users = mdo;
// Clean old data
delete metadataObj.authors;
delete metadataLazyObj.authors;
// Always update the userlist in the lazy object, otherwise it may be outdated
// and metadataMgr.updateMetadata() won't do anything, and so we won't push events
// to the userlist UI ==> phantom viewers
@@ -96,27 +99,6 @@ define(['json.sortify'], function (Sortify) {
checkUpdate(lazy);
});
};
var addAuthor = function () {
if (!meta.user || !meta.user.netfluxId || !priv || !priv.edPublic) { return; }
var authors = metadataObj.authors || {};
var old = Sortify(authors);
if (!authors[priv.edPublic]) {
authors[priv.edPublic] = {
nId: [meta.user.netfluxId],
name: meta.user.name
};
} else {
authors[priv.edPublic].name = meta.user.name;
if (authors[priv.edPublic].nId.indexOf(meta.user.netfluxId) === -1) {
authors[priv.edPublic].nId.push(meta.user.netfluxId);
}
}
if (Sortify(authors) !== old) {
metadataObj.authors = authors;
metadataLazyObj.authors = JSON.parse(JSON.stringify(authors));
change();
}
};
var netfluxId;
var isReady = false;
@@ -225,7 +207,6 @@ define(['json.sortify'], function (Sortify) {
if (isReady) { return void f(); }
readyHandlers.push(f);
},
addAuthor: addAuthor,
});
};
return Object.freeze({ create: create });

View File

@@ -290,7 +290,7 @@ define([
}
if (padChange && hasChanged(content)) {
cpNfInner.metadataMgr.addAuthor();
//cpNfInner.metadataMgr.addAuthor();
}
oldContent = content;

View File

@@ -12,7 +12,7 @@ define([
], function ($, Modes, Themes, Messages, UIElements, MT, Hash, Util, TextCursor, ChainPad) {
var module = {};
var cursorToPos = function(cursor, oldText) {
var cursorToPos = module.cursorToPos = function(cursor, oldText) {
var cLine = cursor.line;
var cCh = cursor.ch;
var pos = 0;
@@ -28,7 +28,7 @@ define([
return pos;
};
var posToCursor = function(position, newText) {
var posToCursor = module.posToCursor = function(position, newText) {
var cursor = {
line: 0,
ch: 0
@@ -58,6 +58,7 @@ define([
editor.save();
var ops = ChainPad.Diff.diff(oldDoc, remoteDoc);
console.log(ops);
var selects = ['selectionStart', 'selectionEnd'].map(function (attr) {
return TextCursor.transformCursor(oldCursor[attr], ops);
});
@@ -415,16 +416,16 @@ define([
/////
var canonicalize = function (t) { return t.replace(/\r\n/g, '\n'); };
var canonicalize = exp.canonicalize = function (t) { return t.replace(/\r\n/g, '\n'); };
exp.contentUpdate = function (newContent, authormarksUpdate, authormarksLocal) {
exp.contentUpdate = function (newContent) {
var oldDoc = canonicalize(editor.getValue());
var remoteDoc = newContent.content;
// setValueAndCursor triggers onLocal, even if we don't make any change to the content
// and it may revert other changes (metadata)
if (oldDoc === remoteDoc && (authormarksUpdate === undefined || authormarksLocal === undefined || JSON.stringify(authormarksUpdate) === JSON.stringify(authormarksLocal))) { return; }
if (oldDoc === remoteDoc) { return; }
exp.setValueAndCursor(oldDoc, remoteDoc);
};