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,