diff --git a/www/common/metadata-manager.js b/www/common/metadata-manager.js index 65269e910..684ddcdd2 100644 --- a/www/common/metadata-manager.js +++ b/www/common/metadata-manager.js @@ -28,7 +28,8 @@ define(['json.sortify'], function (Sortify) { defaultTitle: meta.doc.defaultTitle, //title: meta.doc.defaultTitle, type: meta.doc.type, - users: {} + users: {}, + authors: {} }; metadataLazyObj = JSON.parse(JSON.stringify(metadataObj)); } @@ -77,6 +78,24 @@ define(['json.sortify'], function (Sortify) { 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 isReady = false; @@ -173,7 +192,8 @@ define(['json.sortify'], function (Sortify) { onReady: function (f) { if (isReady) { return void f(); } readyHandlers.push(f); - } + }, + addAuthor: addAuthor, }); }; return Object.freeze({ create: create }); diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index 8bba4d111..263781130 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -251,7 +251,19 @@ define([ 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 (readOnly) { return; } @@ -263,6 +275,9 @@ define([ throw new Error("Content must be an object or array, type is " + typeof(content)); } + if (padChange && hasChanged(content)) { + cpNfInner.metadataMgr.addAuthor(); + } oldContent = content; if (Array.isArray(content)) { @@ -669,7 +684,7 @@ define([ setTextContentGetter: function (tcg) { textContentGetter = tcg; }, // 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. onEditableChange: evEditableStateChange.reg,