', {id: HEADER_ID}).appendTo(APP.$rightside);
- addAvatar($header);
- var $rightside = $('
', {id: HEADER_RIGHT_ID}).appendTo($header);
- addDisplayName($rightside);
- addLink($rightside);
- addDescription(APP.$rightside);
- addViewButton(APP.$rightside); //$rightside);
- addPublicKey(APP.$rightside);
- APP.initialized = true;
- createLeftside();
- }
-
- Cryptpad.removeLoadingScreen();
- };
-
- var onInit = function () {
-
- };
- var onDisconnect = function () {};
- var onChange = function () {};
-
- var andThen = function (profileHash) {
- var secret = Cryptpad.getSecrets('profile', profileHash);
- var readOnly = APP.readOnly = secret.keys && !secret.keys.editKeyStr;
- var listmapConfig = {
- data: {},
- websocketURL: Cryptpad.getWebsocketURL(),
- channel: secret.channel,
- readOnly: readOnly,
- validateKey: secret.keys.validateKey || undefined,
- crypto: Crypto.createEncryptor(secret.keys),
- userName: 'profile',
- logLevel: 1,
- };
- var lm = APP.lm = Listmap.create(listmapConfig);
- lm.proxy.on('create', onInit)
- .on('ready', onReady)
- .on('disconnect', onDisconnect)
- .on('change', [], onChange);
- };
-
- var getOrCreateProfile = function () {
- var obj = Cryptpad.getStore().getProxy().proxy;
- if (obj.profile && obj.profile.view && obj.profile.edit) {
- return void andThen(obj.profile.edit);
- }
- // If the user doesn't have a public profile, ask them if they want to create one
- var todo = function () {
- var secret = Cryptpad.getSecrets();
- obj.profile = {};
- var channel = Cryptpad.createChannelId();
- Cryptpad.pinPads([channel], function (e) {
+ // 3rd case: profile creation (create a new random hash, store it later if needed)
+ if (!Cryptpad.isLoggedIn()) { return; }
+ var hash = Cryptpad.createRandomHash();
+ var secret = Cryptpad.getSecrets('profile', hash);
+ Cryptpad.pinPads([secret.channel], function (e) {
if (e) {
if (e === 'E_OVER_LIMIT') {
- Cryptpad.alert(Messages.pinLimitNotPinned, null, true);
+ // TODO
}
- return void Cryptpad.log(Messages._getKey('profile_error', [e]));
+ return;
+ //return void Cryptpad.log(Messages._getKey('profile_error', [e])) // TODO
}
- obj.profile.edit = Cryptpad.getEditHashFromKeys(channel, secret.keys);
- obj.profile.view = Cryptpad.getViewHashFromKeys(channel, secret.keys);
- andThen(obj.profile.edit);
+ obj.profile = {};
+ obj.profile.edit = Cryptpad.getEditHashFromKeys(secret.channel, secret.keys);
+ obj.profile.view = Cryptpad.getViewHashFromKeys(secret.channel, secret.keys);
+ });
+ return secret;
+ };
+ var addRpc = function (sframeChan, Cryptpad) {
+ // Adding a new avatar from the profile: pin it and store it in the object
+ sframeChan.on('Q_PROFILE_AVATAR_ADD', function (data, cb) {
+ var chanId = Cryptpad.hrefToHexChannelId(data);
+ Cryptpad.pinPads([chanId], function (e) {
+ if (e) { return void cb(e); }
+ Cryptpad.getProxy().profile.avatar = data.url;
+ Cryptpad.whenRealtimeSyncs(Cryptpad.getRealtime(), function () {
+ cb();
+ });
+ });
+ });
+ // Removing the avatar from the profile: unpin it
+ sframeChan.on('Q_PROFILE_AVATAR_REMOVE', function (data, cb) {
+ var chanId = Cryptpad.hrefToHexChannelId(data);
+ Cryptpad.unpinPads([chanId], function (e) {
+ delete Cryptpad.getProxy().profile.avatar;
+ cb(e);
+ });
});
};
-
- Cryptpad.removeLoadingScreen();
-
- if (!Cryptpad.isLoggedIn()) {
- var $p = $('
', {id: CREATE_ID}).append(Messages.profile_register);
- var $a = $('', {
- href: '/register/'
- });
- $('