From 2490ee253ffb88070164e9ef39ea0dd9136da6e7 Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Thu, 17 Aug 2017 18:09:17 +0200 Subject: [PATCH 1/2] Added setDisplayName RPC --- www/common/sframe-common.js | 6 ++++++ www/common/sframe-protocol.js | 3 +++ www/pad2/outer.js | 18 +++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index 75f563beb..2b7f24fcd 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -26,6 +26,12 @@ define([ }); }; + 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) { nThen(function (waitFor) { diff --git a/www/common/sframe-protocol.js b/www/common/sframe-protocol.js index 1893182ff..0d980ed11 100644 --- a/www/common/sframe-protocol.js +++ b/www/common/sframe-protocol.js @@ -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, }); \ No newline at end of file diff --git a/www/pad2/outer.js b/www/pad2/outer.js index 035e02186..017736025 100644 --- a/www/pad2/outer.js +++ b/www/pad2/outer.js @@ -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, From 909bda430233c199bfed897f708e66a550932c0e Mon Sep 17 00:00:00 2001 From: Caleb James DeLisle Date: Thu, 17 Aug 2017 18:26:58 +0200 Subject: [PATCH 2/2] This should fix laxy metadata --- www/common/metadata-manager.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/www/common/metadata-manager.js b/www/common/metadata-manager.js index b2a0cf756..6d20573d9 100644 --- a/www/common/metadata-manager.js +++ b/www/common/metadata-manager.js @@ -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);