Pad titles are now shared with the userdoc

pull/1/head
Yann Flory 8 years ago
parent 721cb8fed1
commit 6363d3fb90

@ -150,7 +150,10 @@ define([
var obj = {content: textValue};
// append the userlist to the hyperjson structure
obj.metadata = userList;
obj.metadata = {
users: userList,
title: document.title
};
// set mode too...
obj.highlightMode = module.highlightMode;
@ -355,6 +358,7 @@ define([
return;
}
document.title = title;
onLocal();
});
});
});
@ -461,14 +465,34 @@ define([
});
};
var updateUserList = function(shjson) {
var updateTitle = function (newTitle) {
if (newTitle === document.title) { return; }
// Change the title now, and set it back to the old value if there is an error
var oldTitle = document.title;
document.title = newTitle;
Cryptpad.setPadTitle(newTitle, function (err, data) {
if (err) {
console.log("Couldn't set pad title");
console.error(err);
document.title = oldTitle;
return;
}
});
};
var updateMetadata = function(shjson) {
// Extract the user list (metadata) from the hyperjson
var hjson = (shjson === "") ? "" : JSON.parse(shjson);
if(hjson && hjson.metadata) {
var userData = hjson.metadata;
var json = (shjson === "") ? "" : JSON.parse(shjson);
if (json && json.metadata) {
if (json.metadata.users) {
var userData = json.metadata.users;
// Update the local user data
addToUserList(userData);
}
if (json.metadata.title) {
updateTitle(json.metadata.title);
}
}
};
var unnotify = module.unnotify = function () {
@ -572,7 +596,7 @@ define([
var shjson = module.realtime.getUserDoc();
// Update the user list (metadata) from the hyperjson
updateUserList(shjson);
updateMetadata(shjson);
var hjson = JSON.parse(shjson);
var remoteDoc = hjson.content;
@ -607,7 +631,10 @@ define([
var localDoc = canonicalize($textarea.val());
var hjson2 = {
content: localDoc,
metadata: userList,
metadata: {
users: userList,
title: document.title
},
highlightMode: highlightMode,
};
var shjson2 = stringify(hjson2);

@ -303,7 +303,12 @@ define([
var stringifyDOM = module.stringifyDOM = function (dom) {
var hjson = Hyperjson.fromDOM(dom, isNotMagicLine, brFilter);
hjson[3] = {metadata: userList};
hjson[3] = {
metadata: {
users: userList,
title: document.title
}
};
return stringify(hjson);
};
@ -343,15 +348,34 @@ define([
}
};
var updateUserList = function(shjson) {
var updateTitle = function (newTitle) {
if (newTitle === document.title) { return; }
// Change the title now, and set it back to the old value if there is an error
var oldTitle = document.title;
document.title = newTitle;
Cryptpad.setPadTitle(newTitle, function (err, data) {
if (err) {
console.log("Couldn't set pad title");
console.error(err);
document.title = oldTitle;
return;
}
});
};
var updateMetadata = function(shjson) {
// Extract the user list (metadata) from the hyperjson
var hjson = JSON.parse(shjson);
var peerUserList = hjson[3];
if(peerUserList && peerUserList.metadata) {
var userData = peerUserList.metadata;
var peerMetadata = hjson[3];
if (peerMetadata && peerMetadata.metadata) {
if (peerMetadata.metadata.users) {
var userData = peerMetadata.metadata.users;
// Update the local user data
addToUserList(userData);
hjson.pop();
}
if (peerMetadata.metadata.title) {
updateTitle(peerMetadata.metadata.title);
}
}
};
@ -378,7 +402,7 @@ define([
cursor.update();
// Update the user list (metadata) from the hyperjson
updateUserList(shjson);
updateMetadata(shjson);
// build a dom from HJSON, diff, and patch the editor
applyHjson(shjson);
@ -519,6 +543,7 @@ define([
return;
}
document.title = title;
editor.fire('change');
});
});
});

@ -604,6 +604,21 @@ define([
break;
}
})
.on('change', ['metadata'], function (o, n, p) {
var newTitle = n.title;
if (newTitle === document.title) { return; }
// Change the title now, and set it back to the old value if there is an error
var oldTitle = document.title;
document.title = newTitle;
Cryptpad.setPadTitle(newTitle, function (err, data) {
if (err) {
console.log("Couldn't set pad title");
console.error(err);
document.title = oldTitle;
return;
}
});
})
.on('remove', [], function (o, p, root) {
//console.log("remove: (%s, [%s])", o, p.join(', '));
//console.log(p, o, p.length);
@ -711,6 +726,13 @@ define([
return;
}
document.title = title;
var proxy = module.rt.proxy;
if (proxy.metadata) {
proxy.metadata.title = title;
}
else {
proxy.metadata = {title: title};
}
});
});
});
@ -838,7 +860,7 @@ define([
// don't initialize until the store is ready.
Cryptpad.ready(function () {
var rt = module.rt = Listmap.create(config);
var rt = window.rt = module.rt = Listmap.create(config);
rt.proxy.on('create', function (info) {
var realtime = module.realtime = info.realtime;
window.location.hash = Cryptpad.getHashFromKeys(info.channel, secret.key);

Loading…
Cancel
Save