Enable friend requests from secure pads

pull/1/head
yflory 7 years ago
parent 147d88d845
commit 88cb4fd83c

@ -134,7 +134,8 @@ define([
var confirmMsg = common.Messages._getKey('contacts_request', [
common.fixHTML(msgData.displayName)
]);
common.confirm(confirmMsg, todo, null, true);
common.onFriendRequest(confirmMsg, todo);
//common.confirm(confirmMsg, todo, null, true);
return;
}
if (msg[0] === "FRIEND_REQ_OK") {
@ -144,9 +145,15 @@ define([
// FIXME clarify this function's name
addToFriendList(common, msgData, function (err) {
if (err) {
return void common.log(common.Messages.contacts_addError);
return void Cryptpad.onFriendComplete({
logText: common.Messages.contacts_addError,
netfluxId: sender
});
}
common.log(common.Messages.contacts_added);
Cryptpad.onFriendComplete({
logText: common.Messages.contacts_added,
netfluxId: sender
});
var msg = ["FRIEND_REQ_ACK", chan];
var msgStr = Crypto.encrypt(JSON.stringify(msg), key);
network.sendto(sender, msgStr);
@ -156,7 +163,10 @@ define([
if (msg[0] === "FRIEND_REQ_NOK") {
var i = pendingRequests.indexOf(sender);
if (i !== -1) { pendingRequests.splice(i, 1); }
common.log(common.Messages.contacts_rejected);
Cryptpad.onFriendComplete({
logText: common.Messages.contacts_rejected,
netfluxId: sender
});
common.changeDisplayName(proxy[common.displayNameKey]);
return;
}
@ -165,9 +175,15 @@ define([
if (!data) { return; }
addToFriendList(common, data, function (err) {
if (err) {
return void common.log(common.Messages.contacts_addError);
return void Cryptpad.onFriendComplete({
logText: common.Messages.contacts_addError,
netfluxId: sender
});
}
common.log(common.Messages.contacts_added);
Cryptpad.onFriendComplete({
logText: common.Messages.contacts_added,
netfluxId: sender
});
});
return;
}

@ -1922,6 +1922,13 @@ define([
delete sessionStorage[newPadPathKey];
}
common.onFriendRequest = function (confirmText, cb) {
common.confirm(confirmText, cb, null, true);
};
common.onFriendComplete = function (data) {
common.log(data.logText);
};
Store.ready(function (err, storeObj) {
store = common.store = env.store = storeObj;
common.addDirectMessageHandler(common);

@ -132,6 +132,9 @@ define([], function () {
getPrivateData : function () {
return priv;
},
getUserData : function () {
return meta.user;
},
getNetfluxId : function () {
return meta.user.netfluxId;
}

@ -103,6 +103,17 @@ define([
ctx.sframeChan.query('Q_GET_FULL_HISTORY', null, cb);
};
// Friends
var pendingFriends = [];
funcs.getPendingFriends = function () {
return pendingFriends.slice();
};
funcs.sendFriendRequest = function (netfluxId) {
ctx.sframeChan.query('Q_SEND_FRIEND_REQUEST', netfluxId, $.noop);
pendingFriends.push(netfluxId);
};
// Feedback
funcs.feedback = function (action, force) {
if (force !== true) {
if (!action) { return; }
@ -297,6 +308,16 @@ define([
ctx.sframeChan.on('EV_RT_CONNECT', function () { CommonRealtime.setConnectionState(true); });
ctx.sframeChan.on('EV_RT_DISCONNECT', function () { CommonRealtime.setConnectionState(false); });
ctx.sframeChan.on('Q_INCOMING_FRIEND_REQUEST', function (confirmMsg, cb) {
Cryptpad.confirm(confirmMsg, cb, null, true);
});
ctx.sframeChan.on('EV_FRIEND_REQUEST', function (data) {
var i = pendingFriends.indexOf(data.sender);
if (i !== -1) { pendingFriends.splice(i, 1); }
Cryptpad.log(data.logText);
});
cb(funcs);
});
} };

@ -74,4 +74,8 @@ define({
// Save a pad as a template using the toolbar button
'Q_SAVE_AS_TEMPLATE': true,
// Friend requests from the userlist
'Q_SEND_FRIEND_REQUEST': true, // Up query
'Q_INCOMING_FRIEND_REQUEST': true, // Down query
'EV_FRIEND_REQUEST': true, // Down event when the request is complete
});

@ -156,7 +156,10 @@ define([
var metadataMgr = config.metadataMgr;
var userData = metadataMgr.getMetadata().users;
var viewers = metadataMgr.getViewers();
var origin = config.metadataMgr.getPrivateData().origin;
var priv = metadataMgr.getPrivateData();
var origin = priv.origin;
var friends = priv.friends;
var user = metadataMgr.getUserData();
// If we are using old pads (readonly unavailable), only editing users are in userList.
// With new pads, we also have readonly users in userList, so we have to intersect with
@ -186,22 +189,20 @@ define([
// Editors
// TODO iframe enable friends
//var pendingFriends = Cryptpad.getPendingInvites();
var pendingFriends = Common.getPendingFriends();
editUsersNames.forEach(function (data) {
var name = data.name || Messages.anonymous;
var $span = $('<span>', {'class': 'avatar'});
var $rightCol = $('<span>', {'class': 'right-col'});
$('<span>', {'class': 'name'}).text(name).appendTo($rightCol);
//var proxy = Cryptpad.getProxy();
//var isMe = data.curvePublic === proxy.curvePublic;
/*if (Cryptpad.isLoggedIn() && data.curvePublic) {
var $nameSpan = $('<span>', {'class': 'name'}).text(name).appendTo($rightCol);
var isMe = data.curvePublic === user.curvePublic;
if (Common.isLoggedIn() && data.curvePublic) {
if (isMe) {
$span.attr('title', Messages._getKey('userlist_thisIsYou', [
name
]));
$nameSpan.text(name);
} else if (!proxy.friends || !proxy.friends[data.curvePublic]) {
} else if (!friends[data.curvePublic]) {
if (pendingFriends.indexOf(data.netfluxId) !== -1) {
$('<span>', {'class': 'friend'}).text(Messages.userlist_pending)
.appendTo($rightCol);
@ -213,11 +214,11 @@ define([
])
}).appendTo($rightCol).click(function (e) {
e.stopPropagation();
Cryptpad.inviteFromUserlist(Cryptpad, data.netfluxId);
Common.sendFriendRequest(data.netfluxId);
});
}
}
}*/
}
if (data.profile) {
$span.addClass('clickable');
$span.click(function () {

@ -104,7 +104,8 @@ define([
readOnly: readOnly,
availableHashes: hashes,
isTemplate: Cryptpad.isTemplate(window.location.href),
feedbackAllowed: Cryptpad.isFeedbackAllowed()
feedbackAllowed: Cryptpad.isFeedbackAllowed(),
friends: Cryptpad.getProxy().friends || {}
}
});
});
@ -173,6 +174,18 @@ define([
Cryptpad.saveAsTemplate(Cryptget.put, data, cb);
});
sframeChan.on('Q_SEND_FRIEND_REQUEST', function (netfluxId, cb) {
Cryptpad.inviteFromUserlist(Cryptpad, netfluxId);
});
Cryptpad.onFriendRequest = function (confirmText, cb) {
sframeChan.query('Q_INCOMING_FRIEND_REQUEST', confirmText, function (err, data) {
cb(data);
});
};
Cryptpad.onFriendComplete = function (data) {
sframeChan.event('EV_FRIEND_REQUEST', data);
};
sframeChan.on('Q_GET_FULL_HISTORY', function (data, cb) {
var network = Cryptpad.getNetwork();
var hkn = network.historyKeeper;

Loading…
Cancel
Save