|
|
|
@ -1242,10 +1242,9 @@ define([
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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 () {
|
|
|
|
@ -1261,11 +1260,12 @@ define([
|
|
|
|
|
}, 200);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the owner was not is the pad metadata, check if it is a friend
|
|
|
|
|
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; }
|
|
|
|
@ -1276,26 +1276,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;
|
|
|
|
@ -1332,6 +1334,28 @@ 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);
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}, 200);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
cb(channel.data || {});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// GET_FULL_HISTORY from sframe-common-outer
|
|
|
|
|
Store.getFullHistory = function (clientId, data, cb) {
|
|
|
|
|
var network = store.network;
|
|
|
|
|