|
|
|
@ -1209,10 +1209,7 @@ define([
|
|
|
|
|
},
|
|
|
|
|
noChainPad: true,
|
|
|
|
|
channel: data.channel,
|
|
|
|
|
validateKey: data.validateKey,
|
|
|
|
|
owners: data.owners,
|
|
|
|
|
password: data.password,
|
|
|
|
|
expire: data.expire,
|
|
|
|
|
metadata: data.metadata,
|
|
|
|
|
network: store.network,
|
|
|
|
|
//readOnly: data.readOnly,
|
|
|
|
|
onConnect: function (wc, sendMessage) {
|
|
|
|
@ -1262,11 +1259,14 @@ define([
|
|
|
|
|
channel.sendMessage(msg, clientId, cb);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// requestPadAccess is used to check if we have a way to contact the owner
|
|
|
|
|
// of the pad AND to send the request if we want
|
|
|
|
|
// data.send === false ==> check if we can contact them
|
|
|
|
|
// data.send === true ==> send the request
|
|
|
|
|
Store.requestPadAccess = function (clientId, data, cb) {
|
|
|
|
|
// Get owners from pad metadata
|
|
|
|
|
// Try to find an owner in our friend list
|
|
|
|
|
// Mailbox...
|
|
|
|
|
var owner = data.owner;
|
|
|
|
|
var channel = channels[data.channel];
|
|
|
|
|
if (!channel) { return void cb({error: 'ENOTFOUND'}); }
|
|
|
|
|
if (!data.send && channel && (!channel.data || !channel.data.channel)) {
|
|
|
|
|
var i = 0;
|
|
|
|
|
var it = setInterval(function () {
|
|
|
|
@ -1277,16 +1277,19 @@ define([
|
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
|
// We'll contact the first owner for whom we know the mailbox
|
|
|
|
|
var fData = channel.data || {};
|
|
|
|
|
if (fData.owners) {
|
|
|
|
|
if (!owner && fData.owners) {
|
|
|
|
|
var friends = store.proxy.friends || {};
|
|
|
|
|
if (Object.keys(friends).length > 1) {
|
|
|
|
|
var owner;
|
|
|
|
|
fData.owners.some(function (edPublic) {
|
|
|
|
|
return Object.keys(friends).some(function (curve) {
|
|
|
|
|
if (curve === "me") { return; }
|
|
|
|
@ -1297,26 +1300,28 @@ define([
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
if (owner) {
|
|
|
|
|
if (data.send) {
|
|
|
|
|
var myData = Messaging.createData(store.proxy);
|
|
|
|
|
delete myData.channel;
|
|
|
|
|
store.mailbox.sendTo('REQUEST_PAD_ACCESS', {
|
|
|
|
|
channel: data.channel,
|
|
|
|
|
user: myData
|
|
|
|
|
}, {
|
|
|
|
|
channel: owner.notifications,
|
|
|
|
|
curvePublic: owner.curvePublic
|
|
|
|
|
}, function () {
|
|
|
|
|
cb({state: true});
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return void cb({state: true});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cb({sent: false});
|
|
|
|
|
|
|
|
|
|
// If send is true, send the request to the owner.
|
|
|
|
|
if (owner) {
|
|
|
|
|
if (data.send) {
|
|
|
|
|
var myData = Messaging.createData(store.proxy);
|
|
|
|
|
delete myData.channel;
|
|
|
|
|
store.mailbox.sendTo('REQUEST_PAD_ACCESS', {
|
|
|
|
|
channel: data.channel,
|
|
|
|
|
user: myData
|
|
|
|
|
}, {
|
|
|
|
|
channel: owner.notifications,
|
|
|
|
|
curvePublic: owner.curvePublic
|
|
|
|
|
}, function () {
|
|
|
|
|
cb({state: true});
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return void cb({state: true});
|
|
|
|
|
}
|
|
|
|
|
cb({state: false});
|
|
|
|
|
};
|
|
|
|
|
Store.givePadAccess = function (clientId, data, cb) {
|
|
|
|
|
var edPublic = store.proxy.edPublic;
|
|
|
|
@ -1353,6 +1358,29 @@ define([
|
|
|
|
|
cb();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Store.getPadMetadata = function (clientId, data, cb) {
|
|
|
|
|
if (!data.channel) { return void cb({ error: 'ENOTFOUND'}); }
|
|
|
|
|
var channel = channels[data.channel];
|
|
|
|
|
if (!channel) { return void cb({ error: 'ENOTFOUND' }); }
|
|
|
|
|
if (!channel.data || !channel.data.channel) {
|
|
|
|
|
var i = 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 || {});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// GET_FULL_HISTORY from sframe-common-outer
|
|
|
|
|
Store.getFullHistory = function (clientId, data, cb) {
|
|
|
|
|
var network = store.network;
|
|
|
|
@ -1459,14 +1487,16 @@ define([
|
|
|
|
|
websocketURL: NetConfig.getWebsocketURL(),
|
|
|
|
|
channel: secret.channel,
|
|
|
|
|
readOnly: false,
|
|
|
|
|
validateKey: secret.keys.validateKey || undefined,
|
|
|
|
|
crypto: Crypto.createEncryptor(secret.keys),
|
|
|
|
|
userName: 'sharedFolder',
|
|
|
|
|
logLevel: 1,
|
|
|
|
|
ChainPad: ChainPad,
|
|
|
|
|
classic: true,
|
|
|
|
|
network: store.network,
|
|
|
|
|
owners: owners
|
|
|
|
|
metadata: {
|
|
|
|
|
validateKey: secret.keys.validateKey || undefined,
|
|
|
|
|
owners: owners
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var rt = Listmap.create(listmapConfig);
|
|
|
|
|
store.sharedFolders[id] = rt;
|
|
|
|
|