Pad titles are now shared with the userdoc
This commit is contained in:
parent
721cb8fed1
commit
6363d3fb90
@ -150,7 +150,10 @@ define([
|
|||||||
var obj = {content: textValue};
|
var obj = {content: textValue};
|
||||||
|
|
||||||
// append the userlist to the hyperjson structure
|
// append the userlist to the hyperjson structure
|
||||||
obj.metadata = userList;
|
obj.metadata = {
|
||||||
|
users: userList,
|
||||||
|
title: document.title
|
||||||
|
};
|
||||||
|
|
||||||
// set mode too...
|
// set mode too...
|
||||||
obj.highlightMode = module.highlightMode;
|
obj.highlightMode = module.highlightMode;
|
||||||
@ -355,6 +358,7 @@ define([
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
document.title = title;
|
document.title = title;
|
||||||
|
onLocal();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -461,13 +465,33 @@ 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
|
// Extract the user list (metadata) from the hyperjson
|
||||||
var hjson = (shjson === "") ? "" : JSON.parse(shjson);
|
var json = (shjson === "") ? "" : JSON.parse(shjson);
|
||||||
if(hjson && hjson.metadata) {
|
if (json && json.metadata) {
|
||||||
var userData = hjson.metadata;
|
if (json.metadata.users) {
|
||||||
// Update the local user data
|
var userData = json.metadata.users;
|
||||||
addToUserList(userData);
|
// Update the local user data
|
||||||
|
addToUserList(userData);
|
||||||
|
}
|
||||||
|
if (json.metadata.title) {
|
||||||
|
updateTitle(json.metadata.title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -572,7 +596,7 @@ define([
|
|||||||
var shjson = module.realtime.getUserDoc();
|
var shjson = module.realtime.getUserDoc();
|
||||||
|
|
||||||
// Update the user list (metadata) from the hyperjson
|
// Update the user list (metadata) from the hyperjson
|
||||||
updateUserList(shjson);
|
updateMetadata(shjson);
|
||||||
|
|
||||||
var hjson = JSON.parse(shjson);
|
var hjson = JSON.parse(shjson);
|
||||||
var remoteDoc = hjson.content;
|
var remoteDoc = hjson.content;
|
||||||
@ -607,7 +631,10 @@ define([
|
|||||||
var localDoc = canonicalize($textarea.val());
|
var localDoc = canonicalize($textarea.val());
|
||||||
var hjson2 = {
|
var hjson2 = {
|
||||||
content: localDoc,
|
content: localDoc,
|
||||||
metadata: userList,
|
metadata: {
|
||||||
|
users: userList,
|
||||||
|
title: document.title
|
||||||
|
},
|
||||||
highlightMode: highlightMode,
|
highlightMode: highlightMode,
|
||||||
};
|
};
|
||||||
var shjson2 = stringify(hjson2);
|
var shjson2 = stringify(hjson2);
|
||||||
|
|||||||
@ -303,7 +303,12 @@ define([
|
|||||||
|
|
||||||
var stringifyDOM = module.stringifyDOM = function (dom) {
|
var stringifyDOM = module.stringifyDOM = function (dom) {
|
||||||
var hjson = Hyperjson.fromDOM(dom, isNotMagicLine, brFilter);
|
var hjson = Hyperjson.fromDOM(dom, isNotMagicLine, brFilter);
|
||||||
hjson[3] = {metadata: userList};
|
hjson[3] = {
|
||||||
|
metadata: {
|
||||||
|
users: userList,
|
||||||
|
title: document.title
|
||||||
|
}
|
||||||
|
};
|
||||||
return stringify(hjson);
|
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
|
// Extract the user list (metadata) from the hyperjson
|
||||||
var hjson = JSON.parse(shjson);
|
var hjson = JSON.parse(shjson);
|
||||||
var peerUserList = hjson[3];
|
var peerMetadata = hjson[3];
|
||||||
if(peerUserList && peerUserList.metadata) {
|
if (peerMetadata && peerMetadata.metadata) {
|
||||||
var userData = peerUserList.metadata;
|
if (peerMetadata.metadata.users) {
|
||||||
// Update the local user data
|
var userData = peerMetadata.metadata.users;
|
||||||
addToUserList(userData);
|
// Update the local user data
|
||||||
hjson.pop();
|
addToUserList(userData);
|
||||||
|
}
|
||||||
|
if (peerMetadata.metadata.title) {
|
||||||
|
updateTitle(peerMetadata.metadata.title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -378,7 +402,7 @@ define([
|
|||||||
cursor.update();
|
cursor.update();
|
||||||
|
|
||||||
// Update the user list (metadata) from the hyperjson
|
// Update the user list (metadata) from the hyperjson
|
||||||
updateUserList(shjson);
|
updateMetadata(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);
|
||||||
@ -519,6 +543,7 @@ define([
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
document.title = title;
|
document.title = title;
|
||||||
|
editor.fire('change');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -604,6 +604,21 @@ define([
|
|||||||
break;
|
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) {
|
.on('remove', [], function (o, p, root) {
|
||||||
//console.log("remove: (%s, [%s])", o, p.join(', '));
|
//console.log("remove: (%s, [%s])", o, p.join(', '));
|
||||||
//console.log(p, o, p.length);
|
//console.log(p, o, p.length);
|
||||||
@ -711,6 +726,13 @@ define([
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
document.title = title;
|
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.
|
// don't initialize until the store is ready.
|
||||||
Cryptpad.ready(function () {
|
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) {
|
rt.proxy.on('create', function (info) {
|
||||||
var realtime = module.realtime = info.realtime;
|
var realtime = module.realtime = info.realtime;
|
||||||
window.location.hash = Cryptpad.getHashFromKeys(info.channel, secret.key);
|
window.location.hash = Cryptpad.getHashFromKeys(info.channel, secret.key);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user