Hide the friend button when the resquest is accepted

pull/1/head
yflory 8 years ago
parent 96fde4e5ed
commit 5b5a7ab286

@ -5,6 +5,8 @@ define([
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) {
var proxy = common.getProxy();
if (!proxy.friends) {
@ -28,6 +30,7 @@ define([
friends[pubKey] = data;
common.whenRealtimeSyncs(common.getRealtime(), cb);
common.changeDisplayName(proxy[common.displayNameKey]);
};
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) {
var network = common.getNetwork();
if (!network) { return void console.error('Network not ready'); }
var proxy = common.getProxy();
network.on('message', function (message, sender) {
var msg;
if (sender === network.historyKeeper) { return; }
@ -60,15 +69,23 @@ define([
msg = JSON.parse(decryptMsg);
if (msg[1] !== parsed.hashData.channel) { return; }
var msgData = msg[2];
var msg;
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.channelHash)];
msgStr = Crypto.encrypt(JSON.stringify(msg), key);
network.sendto(sender, msgStr);
return;
}
common.confirm("Accept friend?", function (yes) { // XXX
var msg = ["FRIEND_REQ_NOK", chan];
if (yes) {
pending[sender] = msgData;
msg = ["FRIEND_REQ_OK", chan, createData(common, msgData.channelHash)];
}
var msgStr = Crypto.encrypt(JSON.stringify(msg), key);
// Send encrypted message
msgStr = Crypto.encrypt(JSON.stringify(msg), key);
network.sendto(sender, msgStr);
});
return;

@ -52,7 +52,8 @@ define(function () {
name: exp.myUserName,
uid: Cryptpad.getUid(),
avatar: Cryptpad.getAvatarUrl(),
profile: Cryptpad.getProfileUrl()
profile: Cryptpad.getProfileUrl(),
edPublic: Cryptpad.getProxy().edPublic
};
addToUserData(myData);
Cryptpad.setAttribute('username', exp.myUserName, function (err) {
@ -81,7 +82,8 @@ define(function () {
name: "",
uid: Cryptpad.getUid(),
avatar: Cryptpad.getAvatarUrl(),
profile: Cryptpad.getProfileUrl()
profile: Cryptpad.getProfileUrl(),
edPublic: Cryptpad.getProxy().edPublic
};
addToUserData(myData);
onLocal();

@ -153,6 +153,14 @@ define([
}
return;
};
common.getUserlist = function () {
if (store) {
if (store.getProxy() && store.getProxy().info) {
return store.getProxy().info.userList;
}
}
return;
};
common.getProfileUrl = function () {
if (store && store.getProfile()) {
return store.getProfile().view;

@ -219,6 +219,10 @@ define([
// Trigger userlist update when the avatar has changed
Cryptpad.changeDisplayName(proxy[Cryptpad.displayNameKey]);
});
proxy.on('change', ['friends'], function () {
// Trigger userlist update when the avatar has changed
Cryptpad.changeDisplayName(proxy[Cryptpad.displayNameKey]);
});
proxy.on('change', [tokenKey], function () {
var localToken = tryParsing(localStorage.getItem(tokenKey));
if (localToken !== proxy[tokenKey]) {

@ -210,13 +210,16 @@ define([
var $span = $('<span>', {'title': name});
var $rightCol = $('<span>', {'class': 'right-col'});
$('<span>', {'class': 'name'}).text(name).appendTo($rightCol);
// TODO: if account
var $button = $('<button>', {'class': 'friend'}).appendTo($rightCol);
$button.text('Add friend').click(function (e) {
e.stopPropagation();
Cryptpad.inviteFromUserlist(Cryptpad, data.netfluxId);
});
// TODO: end if
var proxy = Cryptpad.getProxy();
if (Cryptpad.isLoggedIn() && data.edPublic && data.edPublic !== proxy.edPublic) {
if (!proxy.friends || !proxy.friends[data.edPublic]) {
var $button = $('<button>', {'class': 'friend'}).appendTo($rightCol);
$button.text('Add friend').click(function (e) {
e.stopPropagation();
Cryptpad.inviteFromUserlist(Cryptpad, data.netfluxId);
});
}
}
if (data.profile) {
$span.addClass('clickable');
$span.click(function () {

Loading…
Cancel
Save