Enable friend requests from secure pads
This commit is contained in:
@@ -134,7 +134,8 @@ define([
|
|||||||
var confirmMsg = common.Messages._getKey('contacts_request', [
|
var confirmMsg = common.Messages._getKey('contacts_request', [
|
||||||
common.fixHTML(msgData.displayName)
|
common.fixHTML(msgData.displayName)
|
||||||
]);
|
]);
|
||||||
common.confirm(confirmMsg, todo, null, true);
|
common.onFriendRequest(confirmMsg, todo);
|
||||||
|
//common.confirm(confirmMsg, todo, null, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg[0] === "FRIEND_REQ_OK") {
|
if (msg[0] === "FRIEND_REQ_OK") {
|
||||||
@@ -144,9 +145,15 @@ define([
|
|||||||
// FIXME clarify this function's name
|
// FIXME clarify this function's name
|
||||||
addToFriendList(common, msgData, function (err) {
|
addToFriendList(common, msgData, function (err) {
|
||||||
if (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 msg = ["FRIEND_REQ_ACK", chan];
|
||||||
var msgStr = Crypto.encrypt(JSON.stringify(msg), key);
|
var msgStr = Crypto.encrypt(JSON.stringify(msg), key);
|
||||||
network.sendto(sender, msgStr);
|
network.sendto(sender, msgStr);
|
||||||
@@ -156,7 +163,10 @@ define([
|
|||||||
if (msg[0] === "FRIEND_REQ_NOK") {
|
if (msg[0] === "FRIEND_REQ_NOK") {
|
||||||
var i = pendingRequests.indexOf(sender);
|
var i = pendingRequests.indexOf(sender);
|
||||||
if (i !== -1) { pendingRequests.splice(i, 1); }
|
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]);
|
common.changeDisplayName(proxy[common.displayNameKey]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -165,9 +175,15 @@ define([
|
|||||||
if (!data) { return; }
|
if (!data) { return; }
|
||||||
addToFriendList(common, data, function (err) {
|
addToFriendList(common, data, function (err) {
|
||||||
if (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;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1922,6 +1922,13 @@ define([
|
|||||||
delete sessionStorage[newPadPathKey];
|
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.ready(function (err, storeObj) {
|
||||||
store = common.store = env.store = storeObj;
|
store = common.store = env.store = storeObj;
|
||||||
common.addDirectMessageHandler(common);
|
common.addDirectMessageHandler(common);
|
||||||
|
|||||||
@@ -132,6 +132,9 @@ define([], function () {
|
|||||||
getPrivateData : function () {
|
getPrivateData : function () {
|
||||||
return priv;
|
return priv;
|
||||||
},
|
},
|
||||||
|
getUserData : function () {
|
||||||
|
return meta.user;
|
||||||
|
},
|
||||||
getNetfluxId : function () {
|
getNetfluxId : function () {
|
||||||
return meta.user.netfluxId;
|
return meta.user.netfluxId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,6 +103,17 @@ define([
|
|||||||
ctx.sframeChan.query('Q_GET_FULL_HISTORY', null, cb);
|
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) {
|
funcs.feedback = function (action, force) {
|
||||||
if (force !== true) {
|
if (force !== true) {
|
||||||
if (!action) { return; }
|
if (!action) { return; }
|
||||||
@@ -297,6 +308,16 @@ define([
|
|||||||
ctx.sframeChan.on('EV_RT_CONNECT', function () { CommonRealtime.setConnectionState(true); });
|
ctx.sframeChan.on('EV_RT_CONNECT', function () { CommonRealtime.setConnectionState(true); });
|
||||||
ctx.sframeChan.on('EV_RT_DISCONNECT', function () { CommonRealtime.setConnectionState(false); });
|
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);
|
cb(funcs);
|
||||||
});
|
});
|
||||||
} };
|
} };
|
||||||
|
|||||||
@@ -74,4 +74,8 @@ define({
|
|||||||
// Save a pad as a template using the toolbar button
|
// Save a pad as a template using the toolbar button
|
||||||
'Q_SAVE_AS_TEMPLATE': true,
|
'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 metadataMgr = config.metadataMgr;
|
||||||
var userData = metadataMgr.getMetadata().users;
|
var userData = metadataMgr.getMetadata().users;
|
||||||
var viewers = metadataMgr.getViewers();
|
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.
|
// 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
|
// With new pads, we also have readonly users in userList, so we have to intersect with
|
||||||
@@ -186,22 +189,20 @@ define([
|
|||||||
|
|
||||||
// Editors
|
// Editors
|
||||||
// TODO iframe enable friends
|
// TODO iframe enable friends
|
||||||
//var pendingFriends = Cryptpad.getPendingInvites();
|
var pendingFriends = Common.getPendingFriends();
|
||||||
editUsersNames.forEach(function (data) {
|
editUsersNames.forEach(function (data) {
|
||||||
var name = data.name || Messages.anonymous;
|
var name = data.name || Messages.anonymous;
|
||||||
var $span = $('<span>', {'class': 'avatar'});
|
var $span = $('<span>', {'class': 'avatar'});
|
||||||
var $rightCol = $('<span>', {'class': 'right-col'});
|
var $rightCol = $('<span>', {'class': 'right-col'});
|
||||||
$('<span>', {'class': 'name'}).text(name).appendTo($rightCol);
|
var $nameSpan = $('<span>', {'class': 'name'}).text(name).appendTo($rightCol);
|
||||||
//var proxy = Cryptpad.getProxy();
|
var isMe = data.curvePublic === user.curvePublic;
|
||||||
//var isMe = data.curvePublic === proxy.curvePublic;
|
if (Common.isLoggedIn() && data.curvePublic) {
|
||||||
|
|
||||||
/*if (Cryptpad.isLoggedIn() && data.curvePublic) {
|
|
||||||
if (isMe) {
|
if (isMe) {
|
||||||
$span.attr('title', Messages._getKey('userlist_thisIsYou', [
|
$span.attr('title', Messages._getKey('userlist_thisIsYou', [
|
||||||
name
|
name
|
||||||
]));
|
]));
|
||||||
$nameSpan.text(name);
|
$nameSpan.text(name);
|
||||||
} else if (!proxy.friends || !proxy.friends[data.curvePublic]) {
|
} else if (!friends[data.curvePublic]) {
|
||||||
if (pendingFriends.indexOf(data.netfluxId) !== -1) {
|
if (pendingFriends.indexOf(data.netfluxId) !== -1) {
|
||||||
$('<span>', {'class': 'friend'}).text(Messages.userlist_pending)
|
$('<span>', {'class': 'friend'}).text(Messages.userlist_pending)
|
||||||
.appendTo($rightCol);
|
.appendTo($rightCol);
|
||||||
@@ -213,11 +214,11 @@ define([
|
|||||||
])
|
])
|
||||||
}).appendTo($rightCol).click(function (e) {
|
}).appendTo($rightCol).click(function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
Cryptpad.inviteFromUserlist(Cryptpad, data.netfluxId);
|
Common.sendFriendRequest(data.netfluxId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
if (data.profile) {
|
if (data.profile) {
|
||||||
$span.addClass('clickable');
|
$span.addClass('clickable');
|
||||||
$span.click(function () {
|
$span.click(function () {
|
||||||
|
|||||||
@@ -104,7 +104,8 @@ define([
|
|||||||
readOnly: readOnly,
|
readOnly: readOnly,
|
||||||
availableHashes: hashes,
|
availableHashes: hashes,
|
||||||
isTemplate: Cryptpad.isTemplate(window.location.href),
|
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);
|
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) {
|
sframeChan.on('Q_GET_FULL_HISTORY', function (data, cb) {
|
||||||
var network = Cryptpad.getNetwork();
|
var network = Cryptpad.getNetwork();
|
||||||
var hkn = network.historyKeeper;
|
var hkn = network.historyKeeper;
|
||||||
|
|||||||
Reference in New Issue
Block a user