Keep only one getPadMetadata in outer
This commit is contained in:
@@ -77,6 +77,8 @@ define([
|
|||||||
waitFor.abort();
|
waitFor.abort();
|
||||||
return void cb(err || 'EEMPTY');
|
return void cb(err || 'EEMPTY');
|
||||||
}
|
}
|
||||||
|
delete val.owners;
|
||||||
|
delete val.expire;
|
||||||
Util.extend(data, val);
|
Util.extend(data, val);
|
||||||
if (data.href) { data.href = base + data.href; }
|
if (data.href) { data.href = base + data.href; }
|
||||||
if (data.roHref) { data.roHref = base + data.roHref; }
|
if (data.roHref) { data.roHref = base + data.roHref; }
|
||||||
|
|||||||
@@ -759,7 +759,6 @@ define([
|
|||||||
pad.onMetadataEvent = Util.mkEvent();
|
pad.onMetadataEvent = Util.mkEvent();
|
||||||
|
|
||||||
pad.getPadMetadata = function (data, cb) {
|
pad.getPadMetadata = function (data, cb) {
|
||||||
postMessage('GET_PAD_METADATA', data, cb);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pad.requestAccess = function (data, cb) {
|
pad.requestAccess = function (data, cb) {
|
||||||
@@ -773,10 +772,7 @@ define([
|
|||||||
postMessage('SET_PAD_METADATA', data, cb);
|
postMessage('SET_PAD_METADATA', data, cb);
|
||||||
};
|
};
|
||||||
common.getPadMetadata = function (data, cb) {
|
common.getPadMetadata = function (data, cb) {
|
||||||
common.anonRpcMsg('GET_METADATA', data.channel, function (err, obj) {
|
postMessage('GET_PAD_METADATA', data, cb);
|
||||||
if (err) { return void cb({error: err}); }
|
|
||||||
cb(obj && obj[0]);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
common.changePadPassword = function (Crypt, Crypto, href, newPassword, edPublic, cb) {
|
common.changePadPassword = function (Crypt, Crypto, href, newPassword, edPublic, cb) {
|
||||||
|
|||||||
@@ -1282,32 +1282,15 @@ define([
|
|||||||
// data.send === true ==> send the request
|
// data.send === true ==> send the request
|
||||||
Store.requestPadAccess = function (clientId, data, cb) {
|
Store.requestPadAccess = function (clientId, data, cb) {
|
||||||
var owner = data.owner;
|
var owner = data.owner;
|
||||||
var channel = channels[data.channel];
|
var owners = data.owners;
|
||||||
if (!channel) { return void cb({error: 'ENOTFOUND'}); }
|
|
||||||
if (!data.send && channel && (!channel.data || !channel.data.channel)) {
|
|
||||||
var i = 0;
|
|
||||||
var it = setInterval(function () {
|
|
||||||
if (channel.data && channel.data.channel) {
|
|
||||||
clearInterval(it);
|
|
||||||
Store.requestPadAccess(clientId, data, cb);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (i >= 300) { // One minute timeout
|
|
||||||
clearInterval(it);
|
|
||||||
return void cb({error: 'ETIMEOUT'});
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}, 200);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the owner was not is the pad metadata, check if it is a friend.
|
// If the owner was not is the pad metadata, check if it is a friend.
|
||||||
// We'll contact the first owner for whom we know the mailbox
|
// We'll contact the first owner for whom we know the mailbox
|
||||||
var fData = channel.data || {};
|
if (!owner && Array.isArray(owners)) {
|
||||||
if (!owner && fData.owners) {
|
|
||||||
var friends = store.proxy.friends || {};
|
var friends = store.proxy.friends || {};
|
||||||
if (Object.keys(friends).length > 1) {
|
// If we have friends, check if an owner is one of them (with a mailbox)
|
||||||
fData.owners.some(function (edPublic) {
|
if (Object.keys(friends).filter(function (curve) { return curve !== 'me' }).length) {
|
||||||
|
owners.some(function (edPublic) {
|
||||||
return Object.keys(friends).some(function (curve) {
|
return Object.keys(friends).some(function (curve) {
|
||||||
if (curve === "me") { return; }
|
if (curve === "me") { return; }
|
||||||
if (edPublic === friends[curve].edPublic &&
|
if (edPublic === friends[curve].edPublic &&
|
||||||
@@ -1377,25 +1360,11 @@ define([
|
|||||||
|
|
||||||
Store.getPadMetadata = function (clientId, data, cb) {
|
Store.getPadMetadata = function (clientId, data, cb) {
|
||||||
if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); }
|
if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); }
|
||||||
var channel = channels[data.channel];
|
store.anon_rpc.send('GET_METADATA', data.channel, function (err, obj) {
|
||||||
if (!channel) { return void cb({ error: 'ENOTFOUND' }); }
|
if (err) { return void cb({error: err}); }
|
||||||
if (!channel.data || !channel.data.channel) {
|
// XXX update local owner and expire here
|
||||||
var i = 0;
|
cb((obj && obj[0]) || {});
|
||||||
var it = setInterval(function () {
|
});
|
||||||
if (channel.data && channel.data.channel) {
|
|
||||||
clearInterval(it);
|
|
||||||
Store.getPadMetadata(clientId, data, cb);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (i >= 300) { // One minute timeout
|
|
||||||
clearInterval(it);
|
|
||||||
return void cb({error: 'ETIMEOUT'});
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}, 200);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cb(channel.data || {});
|
|
||||||
};
|
};
|
||||||
Store.setPadMetadata = function (clientId, data, cb) {
|
Store.setPadMetadata = function (clientId, data, cb) {
|
||||||
if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); }
|
if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); }
|
||||||
|
|||||||
@@ -1010,21 +1010,26 @@ define([
|
|||||||
sframeChan.on('EV_GIVE_ACCESS', function (data, cb) {
|
sframeChan.on('EV_GIVE_ACCESS', function (data, cb) {
|
||||||
Cryptpad.padRpc.giveAccess(data, cb);
|
Cryptpad.padRpc.giveAccess(data, cb);
|
||||||
});
|
});
|
||||||
sframeChan.on('Q_REQUEST_ACCESS', function (data, cb) {
|
// REQUEST_ACCESS is used both to check IF we can contact an owner (send === false)
|
||||||
|
// AND also to send the request if we want (send === true)
|
||||||
|
sframeChan.on('Q_REQUEST_ACCESS', function (send, cb) {
|
||||||
if (readOnly && hashes.editHash) {
|
if (readOnly && hashes.editHash) {
|
||||||
return void cb({error: 'ALREADYKNOWN'});
|
return void cb({error: 'ALREADYKNOWN'});
|
||||||
}
|
}
|
||||||
var owner;
|
var owner, owners;
|
||||||
var crypto = Crypto.createEncryptor(secret.keys);
|
var crypto = Crypto.createEncryptor(secret.keys);
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
// Try to get the owner's mailbox from the pad metadata first.
|
// Try to get the owner's mailbox from the pad metadata first.
|
||||||
// If it's is an older owned pad, check if the owner is a friend
|
// If it's is an older owned pad, check if the owner is a friend
|
||||||
// or an acquaintance (from async-store directly in requestAccess)
|
// or an acquaintance (from async-store directly in requestAccess)
|
||||||
Cryptpad.padRpc.getPadMetadata({
|
Cryptpad.getPadMetadata({
|
||||||
channel: secret.channel
|
channel: secret.channel
|
||||||
}, waitFor(function (obj) {
|
}, waitFor(function (obj) {
|
||||||
obj = obj || {};
|
obj = obj || {};
|
||||||
if (obj.error) { return; }
|
if (obj.error) { return; }
|
||||||
|
|
||||||
|
owners = obj.owners;
|
||||||
|
|
||||||
var mailbox;
|
var mailbox;
|
||||||
// Get the first available mailbox (the field can be an string or an object)
|
// Get the first available mailbox (the field can be an string or an object)
|
||||||
// TODO maybe we should send the request to all the owners?
|
// TODO maybe we should send the request to all the owners?
|
||||||
@@ -1043,10 +1048,16 @@ define([
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
|
// If we are just checking (send === false) and there is a mailbox field, cb state true
|
||||||
|
// If there is no mailbox, we'll have to check if an owner is a friend in the worker
|
||||||
|
if (owner && !send) {
|
||||||
|
return void cb({state: true});
|
||||||
|
}
|
||||||
Cryptpad.padRpc.requestAccess({
|
Cryptpad.padRpc.requestAccess({
|
||||||
send: data,
|
send: send,
|
||||||
channel: secret.channel,
|
channel: secret.channel,
|
||||||
owner: owner
|
owner: owner,
|
||||||
|
owners: owners
|
||||||
}, cb);
|
}, cb);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user