Merge branch 'pad2' of github.com:xwiki-labs/cryptpad into pad2
commit
604415b32c
|
@ -4,6 +4,13 @@ define([], function () {
|
|||
var meta = UNINIT;
|
||||
var members = [];
|
||||
var metadataObj = UNINIT;
|
||||
// This object reflects the metadata which is in the document at this moment.
|
||||
// Normally when a person leaves the pad, everybody sees them leave and updates
|
||||
// their metadata, this causes everyone to fight to change the document and
|
||||
// operational transform doesn't like it. So this is a lazy object which is
|
||||
// only updated either:
|
||||
// 1. On changes to the metadata that come in from someone else
|
||||
// 2. On changes connects, disconnects or changes to your own metadata
|
||||
var metadataLazyObj = UNINIT;
|
||||
var priv = {};
|
||||
var dirty = true;
|
||||
|
@ -37,7 +44,8 @@ define([], function () {
|
|||
//if (!containsYou) { mdo[meta.user.netfluxId] = meta.user; }
|
||||
mdo[meta.user.netfluxId] = meta.user;
|
||||
metadataObj.users = mdo;
|
||||
if (lazy) {
|
||||
var lazyUserStr = JSON.stringify(metadataLazyObj.users[meta.user.netfluxId]);
|
||||
if (lazy || lazyUserStr !== JSON.stringify(meta.user)) {
|
||||
metadataLazyObj.users = mdo;
|
||||
}
|
||||
|
||||
|
@ -81,8 +89,9 @@ define([], function () {
|
|||
return Object.freeze({
|
||||
updateMetadata: function (m) {
|
||||
if (JSON.stringify(metadataObj) === JSON.stringify(m)) { return; }
|
||||
metadataObj = m;
|
||||
change(true);
|
||||
metadataObj = JSON.parse(JSON.stringify(m));
|
||||
metadataLazyObj = JSON.parse(JSON.stringify(m));
|
||||
change(false);
|
||||
},
|
||||
getMetadata: function () {
|
||||
checkUpdate(false);
|
||||
|
|
|
@ -36,6 +36,11 @@ define([
|
|||
return ctx.cpNfInner.metadataMgr.getMetadata().defaultTitle;
|
||||
};
|
||||
|
||||
funcs.setDisplayName = function (name, cb) {
|
||||
ctx.sframeChan.query('Q_SETTINGS_SET_DISPLAY_NAME', name, function (err) {
|
||||
if (cb) { cb(err); }
|
||||
});
|
||||
};
|
||||
|
||||
Object.freeze(funcs);
|
||||
return { create: function (cb) {
|
||||
|
|
|
@ -41,4 +41,7 @@ define({
|
|||
// iframe and synchronized with the other users. This will not trigger a EV_METADATA_UPDATE
|
||||
// because the metadata contained in EV_METADATA_UPDATE does not contain the pad title.
|
||||
'Q_SET_PAD_TITLE_IN_DRIVE': true,
|
||||
|
||||
// Update the user's display-name which will be shown to contacts and people in the same pads.
|
||||
'Q_SETTINGS_SET_DISPLAY_NAME': true,
|
||||
});
|
|
@ -33,7 +33,10 @@ define([
|
|||
//console.log('EV_METADATA_UPDATE');
|
||||
var name;
|
||||
nThen(function (waitFor) {
|
||||
Cryptpad.getLastName(waitFor(function (n) { name = n }));
|
||||
Cryptpad.getLastName(waitFor(function (err, n) {
|
||||
if (err) { console.log(err); }
|
||||
name = n;
|
||||
}));
|
||||
}).nThen(function (waitFor) {
|
||||
sframeChan.event('EV_METADATA_UPDATE', {
|
||||
doc: {
|
||||
|
@ -71,6 +74,19 @@ define([
|
|||
});
|
||||
});
|
||||
|
||||
sframeChan.on('Q_SETTINGS_SET_DISPLAY_NAME', function (newName, cb) {
|
||||
Cryptpad.setAttribute('username', newName, function (err) {
|
||||
if (err) {
|
||||
console.log("Couldn't set username");
|
||||
console.error(err);
|
||||
cb('ERROR');
|
||||
return;
|
||||
}
|
||||
Cryptpad.changeDisplayName(newName, true);
|
||||
cb();
|
||||
});
|
||||
});
|
||||
|
||||
CpNfOuter.start({
|
||||
sframeChan: sframeChan,
|
||||
channel: secret.channel,
|
||||
|
|
Loading…
Reference in New Issue