Store authors of a pad in the metadata
This commit is contained in:
parent
0b5d08649f
commit
5a629e8681
@ -28,7 +28,8 @@ define(['json.sortify'], function (Sortify) {
|
|||||||
defaultTitle: meta.doc.defaultTitle,
|
defaultTitle: meta.doc.defaultTitle,
|
||||||
//title: meta.doc.defaultTitle,
|
//title: meta.doc.defaultTitle,
|
||||||
type: meta.doc.type,
|
type: meta.doc.type,
|
||||||
users: {}
|
users: {},
|
||||||
|
authors: {}
|
||||||
};
|
};
|
||||||
metadataLazyObj = JSON.parse(JSON.stringify(metadataObj));
|
metadataLazyObj = JSON.parse(JSON.stringify(metadataObj));
|
||||||
}
|
}
|
||||||
@ -77,6 +78,24 @@ define(['json.sortify'], function (Sortify) {
|
|||||||
checkUpdate(lazy);
|
checkUpdate(lazy);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
var addAuthor = function () {
|
||||||
|
if (!meta.user || !meta.user.netfluxId || !priv || !priv.edPublic) { return; }
|
||||||
|
var authors = metadataObj.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
metadataObj.authors = authors;
|
||||||
|
metadataLazyObj.authors = JSON.parse(JSON.stringify(authors));
|
||||||
|
change();
|
||||||
|
};
|
||||||
|
|
||||||
var netfluxId;
|
var netfluxId;
|
||||||
var isReady = false;
|
var isReady = false;
|
||||||
@ -173,7 +192,8 @@ define(['json.sortify'], function (Sortify) {
|
|||||||
onReady: function (f) {
|
onReady: function (f) {
|
||||||
if (isReady) { return void f(); }
|
if (isReady) { return void f(); }
|
||||||
readyHandlers.push(f);
|
readyHandlers.push(f);
|
||||||
}
|
},
|
||||||
|
addAuthor: addAuthor,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return Object.freeze({ create: create });
|
return Object.freeze({ create: create });
|
||||||
|
|||||||
@ -251,7 +251,19 @@ define([
|
|||||||
if (!bool && update) { onRemote(); }
|
if (!bool && update) { onRemote(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
onLocal = function () {
|
var hasChanged = function (content) {
|
||||||
|
try {
|
||||||
|
var oldValue = JSON.parse(cpNfInner.chainpad.getUserDoc());
|
||||||
|
if (Array.isArray(content)) {
|
||||||
|
return JSONSortify(content) !== JSONSortify(normalize(oldValue));
|
||||||
|
} else if (content.content) {
|
||||||
|
return content.content !== oldValue.content;
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
onLocal = function (padChange) {
|
||||||
if (state !== STATE.READY) { return; }
|
if (state !== STATE.READY) { return; }
|
||||||
if (readOnly) { return; }
|
if (readOnly) { return; }
|
||||||
|
|
||||||
@ -263,6 +275,9 @@ define([
|
|||||||
throw new Error("Content must be an object or array, type is " + typeof(content));
|
throw new Error("Content must be an object or array, type is " + typeof(content));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (padChange && hasChanged(content)) {
|
||||||
|
cpNfInner.metadataMgr.addAuthor();
|
||||||
|
}
|
||||||
oldContent = content;
|
oldContent = content;
|
||||||
|
|
||||||
if (Array.isArray(content)) {
|
if (Array.isArray(content)) {
|
||||||
@ -669,7 +684,7 @@ define([
|
|||||||
setTextContentGetter: function (tcg) { textContentGetter = tcg; },
|
setTextContentGetter: function (tcg) { textContentGetter = tcg; },
|
||||||
|
|
||||||
// Inform the framework that the content of the pad has been changed locally.
|
// Inform the framework that the content of the pad has been changed locally.
|
||||||
localChange: onLocal,
|
localChange: function () { onLocal(true); },
|
||||||
|
|
||||||
// Register to be informed if the state (whether the document is editable) changes.
|
// Register to be informed if the state (whether the document is editable) changes.
|
||||||
onEditableChange: evEditableStateChange.reg,
|
onEditableChange: evEditableStateChange.reg,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user