From 53b2644b64436c70439ab3d1ac8d0c892e6a2736 Mon Sep 17 00:00:00 2001 From: Yann Flory Date: Tue, 26 Apr 2016 17:16:58 +0200 Subject: [PATCH] Fix a issue with fights over usernames --- www/pad/main.js | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/www/pad/main.js b/www/pad/main.js index 9b50902c7..35848477b 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -60,10 +60,6 @@ define([ return hj; }; - var stringifyDOM = function (dom) { - return stringify(Hyperjson.fromDOM(dom, isNotMagicLine, brFilter)); - }; - var andThen = function (Ckeditor) { /* This is turned off because we prefer that the channel name be chosen by the server, not generated by the client. @@ -232,6 +228,12 @@ define([ (DD).apply(inner, patch); }; + var stringifyDOM = function (dom) { + var hjson = Hyperjson.fromDOM(dom, isNotMagicLine, brFilter); + hjson[3] = {metadata: userList}; + return stringify(hjson); + }; + var realtimeOptions = { // provide initialstate... initialState: stringifyDOM(inner) || '{}', @@ -268,7 +270,6 @@ define([ addToUserList(userData); hjson.pop(); } - return hjson; } var onRemote = realtimeOptions.onRemote = function (info) { @@ -279,15 +280,12 @@ define([ // remember where the cursor is cursor.update(); - // Extract the user list (metadata) from the hyperjson - var hjson = updateUserList(shjson); + // Update the user list (metadata) from the hyperjson + updateUserList(shjson); // build a dom from HJSON, diff, and patch the editor applyHjson(shjson); - // Build a new stringified Chainpad hyperjson without metadata to compare with the one build from the dom - shjson = stringify(hjson); - var shjson2 = stringifyDOM(inner); if (shjson2 !== shjson) { console.error("shjson2 !== shjson"); @@ -337,15 +335,8 @@ define([ var onLocal = realtimeOptions.onLocal = function () { if (initializing) { return; } - // serialize your DOM into an object - var hjson = Hyperjson.fromDOM(inner, isNotMagicLine, brFilter); - - // append the userlist to the hyperjson structure - if(Object.keys(myData).length > 0) { - hjson[3] = {metadata: userList}; - } // stringify the json and send it into chainpad - var shjson = stringify(hjson); + var shjson = stringifyDOM(inner); module.patchText(shjson); if (module.realtime.getUserDoc() !== shjson) {