|
|
@ -5,6 +5,8 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var pending = {};
|
|
|
|
var pending = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove should be called from the friend app at the moment
|
|
|
|
|
|
|
|
// The other user will know it from the private channel ("REMOVE_FRIEND" message?)
|
|
|
|
Msg.removeFromFriendList = function (common, edPublic, cb) {
|
|
|
|
Msg.removeFromFriendList = function (common, edPublic, cb) {
|
|
|
|
var proxy = common.getProxy();
|
|
|
|
var proxy = common.getProxy();
|
|
|
|
if (!proxy.friends) {
|
|
|
|
if (!proxy.friends) {
|
|
|
@ -28,6 +30,7 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
friends[pubKey] = data;
|
|
|
|
friends[pubKey] = data;
|
|
|
|
common.whenRealtimeSyncs(common.getRealtime(), cb);
|
|
|
|
common.whenRealtimeSyncs(common.getRealtime(), cb);
|
|
|
|
|
|
|
|
common.changeDisplayName(proxy[common.displayNameKey]);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var createData = function (common, hash) {
|
|
|
|
var createData = function (common, hash) {
|
|
|
@ -41,9 +44,15 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var getFriend = function (common, pubkey) {
|
|
|
|
|
|
|
|
var proxy = common.getProxy();
|
|
|
|
|
|
|
|
return proxy.friends ? proxy.friends[pubkey] : undefined;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Msg.addDirectMessageHandler = function (common) {
|
|
|
|
Msg.addDirectMessageHandler = function (common) {
|
|
|
|
var network = common.getNetwork();
|
|
|
|
var network = common.getNetwork();
|
|
|
|
if (!network) { return void console.error('Network not ready'); }
|
|
|
|
if (!network) { return void console.error('Network not ready'); }
|
|
|
|
|
|
|
|
var proxy = common.getProxy();
|
|
|
|
network.on('message', function (message, sender) {
|
|
|
|
network.on('message', function (message, sender) {
|
|
|
|
var msg;
|
|
|
|
var msg;
|
|
|
|
if (sender === network.historyKeeper) { return; }
|
|
|
|
if (sender === network.historyKeeper) { return; }
|
|
|
@ -60,15 +69,23 @@ define([
|
|
|
|
msg = JSON.parse(decryptMsg);
|
|
|
|
msg = JSON.parse(decryptMsg);
|
|
|
|
if (msg[1] !== parsed.hashData.channel) { return; }
|
|
|
|
if (msg[1] !== parsed.hashData.channel) { return; }
|
|
|
|
var msgData = msg[2];
|
|
|
|
var msgData = msg[2];
|
|
|
|
|
|
|
|
var msg;
|
|
|
|
|
|
|
|
var msgStr;
|
|
|
|
if (msg[0] === "FRIEND_REQ") {
|
|
|
|
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.channelHash)];
|
|
|
|
|
|
|
|
msgStr = Crypto.encrypt(JSON.stringify(msg), key);
|
|
|
|
|
|
|
|
network.sendto(sender, msgStr);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
common.confirm("Accept friend?", function (yes) { // XXX
|
|
|
|
common.confirm("Accept friend?", function (yes) { // XXX
|
|
|
|
var msg = ["FRIEND_REQ_NOK", chan];
|
|
|
|
|
|
|
|
if (yes) {
|
|
|
|
if (yes) {
|
|
|
|
pending[sender] = msgData;
|
|
|
|
pending[sender] = msgData;
|
|
|
|
msg = ["FRIEND_REQ_OK", chan, createData(common, msgData.channelHash)];
|
|
|
|
msg = ["FRIEND_REQ_OK", chan, createData(common, msgData.channelHash)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var msgStr = Crypto.encrypt(JSON.stringify(msg), key);
|
|
|
|
msgStr = Crypto.encrypt(JSON.stringify(msg), key);
|
|
|
|
// Send encrypted message
|
|
|
|
|
|
|
|
network.sendto(sender, msgStr);
|
|
|
|
network.sendto(sender, msgStr);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|