Fix a issue with fights over usernames

pull/1/head
Yann Flory 9 years ago
parent 85d5f5c47f
commit 53b2644b64

@ -60,10 +60,6 @@ define([
return hj; return hj;
}; };
var stringifyDOM = function (dom) {
return stringify(Hyperjson.fromDOM(dom, isNotMagicLine, brFilter));
};
var andThen = function (Ckeditor) { var andThen = function (Ckeditor) {
/* This is turned off because we prefer that the channel name /* This is turned off because we prefer that the channel name
be chosen by the server, not generated by the client. be chosen by the server, not generated by the client.
@ -232,6 +228,12 @@ define([
(DD).apply(inner, patch); (DD).apply(inner, patch);
}; };
var stringifyDOM = function (dom) {
var hjson = Hyperjson.fromDOM(dom, isNotMagicLine, brFilter);
hjson[3] = {metadata: userList};
return stringify(hjson);
};
var realtimeOptions = { var realtimeOptions = {
// provide initialstate... // provide initialstate...
initialState: stringifyDOM(inner) || '{}', initialState: stringifyDOM(inner) || '{}',
@ -268,7 +270,6 @@ define([
addToUserList(userData); addToUserList(userData);
hjson.pop(); hjson.pop();
} }
return hjson;
} }
var onRemote = realtimeOptions.onRemote = function (info) { var onRemote = realtimeOptions.onRemote = function (info) {
@ -279,15 +280,12 @@ define([
// remember where the cursor is // remember where the cursor is
cursor.update(); cursor.update();
// Extract the user list (metadata) from the hyperjson // Update the user list (metadata) from the hyperjson
var hjson = updateUserList(shjson); updateUserList(shjson);
// build a dom from HJSON, diff, and patch the editor // build a dom from HJSON, diff, and patch the editor
applyHjson(shjson); 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); var shjson2 = stringifyDOM(inner);
if (shjson2 !== shjson) { if (shjson2 !== shjson) {
console.error("shjson2 !== shjson"); console.error("shjson2 !== shjson");
@ -337,15 +335,8 @@ define([
var onLocal = realtimeOptions.onLocal = function () { var onLocal = realtimeOptions.onLocal = function () {
if (initializing) { return; } 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 // stringify the json and send it into chainpad
var shjson = stringify(hjson); var shjson = stringifyDOM(inner);
module.patchText(shjson); module.patchText(shjson);
if (module.realtime.getUserDoc() !== shjson) { if (module.realtime.getUserDoc() !== shjson) {

Loading…
Cancel
Save