', {'class':'chat'}).data('key', edPublic).appendTo($msgContainer);
- createChatBox(common, $chat, edPublic);
+ $chat = $('
', {'class':'chat'})
+ .data('key', curvePublic).appendTo($msgContainer);
+ createChatBox(common, $chat, curvePublic);
isNew = true;
}
// Show the correct div
$msgContainer.find('.chat').hide();
$chat.show();
- Msg.active = edPublic;
+ Msg.active = curvePublic;
- refresh(edPublic);
+ refresh(curvePublic);
};
- var remove = function (edPublic) {
- var data = getFriend(common, edPublic);
+ var remove = function (curvePublic) {
+ var data = getFriend(common, curvePublic);
var channel = channels[data.channel];
//var newdata = createData(common, data.channel);
- var msg = [Types.unfriend, proxy.edPublic, +new Date()];
+ var msg = [Types.unfriend, proxy.curvePublic, +new Date()];
var msgStr = JSON.stringify(msg);
var cryptMsg = channel.encryptor.encrypt(msgStr);
channel.wc.bcast(cryptMsg).then(function () {
- removeFromFriendList(common, edPublic, function () {
+ removeFromFriendList(common, curvePublic, function () {
channel.wc.leave(Types.unfriend);
channel.removeUI();
});
@@ -339,34 +392,34 @@ define([
common.getFriendListUI(common, display, remove).appendTo($listContainer);
// Notify on new messages
- var notify = function (edPublic) {
- if (Msg.active === edPublic) { return; }
+ var notify = function (curvePublic) {
+ if (Msg.active === curvePublic) { return; }
var $friend = $listContainer.find('.friend').filter(function (idx, el) {
- return $(el).data('key') === edPublic;
+ return $(el).data('key') === curvePublic;
});
$friend.addClass('notify');
};
- var unnotify = function (edPublic) {
+ var unnotify = function (curvePublic) {
var $friend = $listContainer.find('.friend').filter(function (idx, el) {
- return $(el).data('key') === edPublic;
+ return $(el).data('key') === curvePublic;
});
$friend.removeClass('notify');
};
- var removeUI = function (edPublic) {
+ var removeUI = function (curvePublic) {
var $friend = $listContainer.find('.friend').filter(function (idx, el) {
- return $(el).data('key') === edPublic;
+ return $(el).data('key') === curvePublic;
});
$friend.remove();
};
- var updateUI = function (edPublic, types) {
- var data = getFriend(common, edPublic);
+ var updateUI = function (curvePublic, types) {
+ var data = getFriend(common, curvePublic);
var chan = channels[data.channel];
if (!chan.ready) {
chan.updateOnReady = (chan.updateOnReady || []).concat(types);
return;
}
var $friend = $listContainer.find('.friend').filter(function (idx, el) {
- return $(el).data('key') === edPublic;
+ return $(el).data('key') === curvePublic;
});
if (types.indexOf('displayName') >= 0) {
$friend.find('.name').text(data.displayName);
@@ -380,7 +433,6 @@ define([
common.displayAvatar($friend, data.avatar, data.displayName, function ($img) {
if (data.avatar && $img) {
avatars[data.avatar] = $img[0].outerHTML;
-
}
});
}
@@ -388,22 +440,24 @@ define([
};
// Open the channels
- Object.keys(friends).forEach(function (f) {
+ var openFriendChannel = function (f) {
+ if (f === "me") { return; }
var data = friends[f];
var keys = Curve.deriveKeys(data.curvePublic, proxy.curvePrivate);
var encryptor = Curve.createEncryptor(keys);
- channels[data.channel] = {
- keys: keys,
- encryptor: encryptor,
- messages: [],
- refresh: function () { refresh(data.edPublic); },
- notify: function () { notify(data.edPublic); },
- unnotify: function () { unnotify(data.edPublic); },
- removeUI: function () { removeUI(data.edPublic); },
- updateUI: function (types) { updateUI(data.edPublic, types); }
- };
network.join(data.channel).then(function (chan) {
- channels[data.channel].wc = chan;
+ channels[data.channel] = {
+ friendEd: f,
+ keys: keys,
+ encryptor: encryptor,
+ messages: [],
+ refresh: function () { refresh(data.curvePublic); },
+ notify: function () { notify(data.curvePublic); },
+ unnotify: function () { unnotify(data.curvePublic); },
+ removeUI: function () { removeUI(data.curvePublic); },
+ updateUI: function (types) { updateUI(data.curvePublic, types); },
+ wc: chan
+ };
chan.on('message', function (msg, sender) {
onMessage(common, msg, sender, chan);
});
@@ -420,22 +474,24 @@ define([
}, function (err) {
console.error(err);
});
- });
+ };
+ Object.keys(friends).forEach(openFriendChannel);
- common.onDisplayNameChanged(function() {
- Object.keys(channels).forEach(function (chan) {
- var channel = channels[chan];
- var newdata = createData(common, chan);
- delete newdata.channel;
- var msg = [Types.update, proxy.edPublic, +new Date(), newdata];
- var msgStr = JSON.stringify(msg);
- var cryptMsg = channel.encryptor.encrypt(msgStr);
- channel.wc.bcast(cryptMsg).then(function () {
- channel.refresh();
- }, function (err) {
- console.error(err);
+ var checkNewFriends = function () {
+ Object.keys(friends).forEach(function (f) {
+ var $friend = $listContainer.find('.friend').filter(function (idx, el) {
+ return $(el).data('key') === f;
});
+ if (!$friend.length) {
+ openFriendChannel(f);
+ addToFriendListUI(common, $listContainer.find('> div'), display, remove, f);
+ }
});
+ };
+
+ common.onDisplayNameChanged(function () {
+ checkNewFriends();
+ updateMyData(common);
});
};
@@ -447,12 +503,12 @@ define([
proxy.friends = {};
}
var friends = proxy.friends;
- var pubKey = data.edPublic;
+ var pubKey = data.curvePublic;
- if (pubKey === proxy.edPublic) { return void cb("E_MYKEY"); }
- if (friends[pubKey]) { return void cb("E_EXISTS"); }
+ if (pubKey === proxy.curvePublic) { return void cb("E_MYKEY"); }
friends[pubKey] = data;
+
common.whenRealtimeSyncs(common.getRealtime(), function () {
common.pinPads([data.channel], cb);
});
@@ -481,21 +537,20 @@ define([
var msgStr;
if (msg[0] === "FRIEND_REQ") {
msg = ["FRIEND_REQ_NOK", chan];
- var existing = getFriend(common, msgData.edPublic);
- if (existing) {
- msg = ["FRIEND_REQ_OK", chan, createData(common, existing.channel)];
- msgStr = Crypto.encrypt(JSON.stringify(msg), key);
- network.sendto(sender, msgStr);
- return;
- }
- common.confirm("Accept friend?", function (yes) { // XXX
+ var todo = function (yes) {
if (yes) {
pending[sender] = msgData;
msg = ["FRIEND_REQ_OK", chan, createData(common, msgData.channel)];
}
msgStr = Crypto.encrypt(JSON.stringify(msg), key);
network.sendto(sender, msgStr);
- });
+ };
+ var existing = getFriend(common, msgData.curvePublic);
+ if (existing) {
+ todo(true);
+ return;
+ }
+ common.confirm("Accept friend?", todo);// TODO
return;
}
if (msg[0] === "FRIEND_REQ_OK") {
diff --git a/www/common/common-userlist.js b/www/common/common-userlist.js
index d93f02015..e7f2449fa 100644
--- a/www/common/common-userlist.js
+++ b/www/common/common-userlist.js
@@ -53,7 +53,7 @@ define(function () {
uid: Cryptpad.getUid(),
avatar: Cryptpad.getAvatarUrl(),
profile: Cryptpad.getProfileUrl(),
- edPublic: Cryptpad.getProxy().edPublic
+ curvePublic: Cryptpad.getProxy().curvePublic
};
addToUserData(myData);
/*Cryptpad.setAttribute('username', exp.myUserName, function (err) {
@@ -84,7 +84,7 @@ define(function () {
uid: Cryptpad.getUid(),
avatar: Cryptpad.getAvatarUrl(),
profile: Cryptpad.getProfileUrl(),
- edPublic: Cryptpad.getProxy().edPublic
+ curvePublic: Cryptpad.getProxy().curvePublic
};
addToUserData(myData);
onLocal();
diff --git a/www/common/toolbar2.js b/www/common/toolbar2.js
index 0a178640f..ffb8f2b10 100644
--- a/www/common/toolbar2.js
+++ b/www/common/toolbar2.js
@@ -200,7 +200,6 @@ define([
// Update the userlist
var $editUsers = $userlistContent.find('.' + USERLIST_CLS).html('');
-
var $editUsersList = $('
', {'class': 'userlist-others'});
// Editors
@@ -210,13 +209,14 @@ define([
var $rightCol = $('', {'class': 'right-col'});
var $nameSpan = $('', {'class': 'name'}).text(name).appendTo($rightCol);
var proxy = Cryptpad.getProxy();
- var isMe = data.edPublic === proxy.edPublic;
- if (Cryptpad.isLoggedIn() && data.edPublic) {
+ var isMe = data.curvePublic === proxy.curvePublic;
+
+ if (Cryptpad.isLoggedIn() && data.curvePublic) {
if (isMe) {
$nameSpan.attr('title', Messages._getKey('userlist_thisIsYou', [
name
])).text(name);
- } else if (!proxy.friends || !proxy.friends[data.edPublic]) {
+ } else if (!proxy.friends || !proxy.friends[data.curvePublic]) {
$('', {
'class': 'fa fa-user-plus friend',
'title': Messages._getKey('userlist_addAsFriendTitle', [
@@ -777,8 +777,14 @@ define([
});
});
Cryptpad.onDisplayNameChanged(function () {
- Cryptpad.findCancelButton().click();
- updateDisplayName(toolbar, config);
+ window.setTimeout(function () {
+ Cryptpad.findCancelButton().click();
+ if (config.userList) {
+ updateUserList(toolbar, config);
+ return;
+ }
+ updateDisplayName(toolbar, config);
+ }, 0);
});
updateDisplayName(toolbar, config);