From 8e08f1b3e5907028df135d56e0a19fe317878585 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 27 Apr 2020 10:46:34 +0200 Subject: [PATCH] Don't add author data for anonymous users --- www/pad/comments.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/www/pad/comments.js b/www/pad/comments.js index 233bb3a13..3606e1d29 100644 --- a/www/pad/comments.js +++ b/www/pad/comments.js @@ -66,8 +66,13 @@ define([ return uid || authorUid(existing); }; + // Return the author ID and add/update the data for registered users + // Return the username for unregistered users var updateAuthorData = function (Env) { var userData = Env.metadataMgr.getUserData(); + if (!Env.common.isLoggedIn()) { + return userData.name; + } var myAuthorId = getAuthorId(Env, userData.curvePublic); var data = Env.comments.authors[myAuthorId] = Env.comments.authors[myAuthorId] || {}; data.name = userData.name; @@ -184,7 +189,9 @@ define([ var content = []; obj.m.forEach(function (msg, i) { - var author = (Env.comments.authors || {})[msg.u] || {}; + var author = typeof(msg.u) === "number" ? + ((Env.comments.authors || {})[msg.u] || {}) : + { name: msg.u }; var name = Util.fixHTML(author.name || Messages.anonymous); var date = new Date(msg.t); var avatar = h('span.cp-avatar'); @@ -257,9 +264,9 @@ define([ }).join('\n'); // Push the reply - var myId = updateAuthorData(Env); + var user = updateAuthorData(Env); obj.m.push({ - u: myId, + u: user, // id (number) or name (string) t: +new Date(), m: val, v: value @@ -477,10 +484,10 @@ define([ // Don't override existing data if (Env.comments.data[uid]) { return; } - var myId = updateAuthorData(Env); + var user = updateAuthorData(Env); Env.comments.data[uid] = { m: [{ - u: myId, + u: user, // Id or name t: +new Date(), m: val, v: canonicalize(Env.editor.getSelection().getSelectedText())