|
|
@ -137,10 +137,9 @@ proxy.mailboxes = {
|
|
|
|
var dismiss = function (ctx, data, cId, cb) {
|
|
|
|
var dismiss = function (ctx, data, cId, cb) {
|
|
|
|
var type = data.type;
|
|
|
|
var type = data.type;
|
|
|
|
var hash = data.hash;
|
|
|
|
var hash = data.hash;
|
|
|
|
var m = Util.find(ctx, ['store', 'proxy', 'mailboxes', type]);
|
|
|
|
|
|
|
|
if (!m) { return void cb({error: 'NOT_FOUND'}); }
|
|
|
|
|
|
|
|
var box = ctx.boxes[type];
|
|
|
|
var box = ctx.boxes[type];
|
|
|
|
if (!box) { return void cb({error: 'NOT_LOADED'}); }
|
|
|
|
if (!box) { return void cb({error: 'NOT_LOADED'}); }
|
|
|
|
|
|
|
|
var m = box.data || {};
|
|
|
|
|
|
|
|
|
|
|
|
// If the hash in in our history, get the index from the history:
|
|
|
|
// If the hash in in our history, get the index from the history:
|
|
|
|
// - if the index is 0, we can change our lastKnownHash
|
|
|
|
// - if the index is 0, we can change our lastKnownHash
|
|
|
@ -202,7 +201,16 @@ proxy.mailboxes = {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var openChannel = function (ctx, type, m, onReady) {
|
|
|
|
var leaveChannel = function (ctx, type, cb) {
|
|
|
|
|
|
|
|
var box = ctx.boxes[type];
|
|
|
|
|
|
|
|
if (!box) { return void cb(); }
|
|
|
|
|
|
|
|
if (!box.cpNf || typeof(box.cpNf.stop) !== "function") { return void cb('EINVAL'); }
|
|
|
|
|
|
|
|
box.cpNf.stop();
|
|
|
|
|
|
|
|
delete ctx.boxes[type];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var openChannel = function (ctx, type, m, onReady, opts) {
|
|
|
|
|
|
|
|
console.error(type, m, opts);
|
|
|
|
|
|
|
|
opts = opts || {};
|
|
|
|
var box = ctx.boxes[type] = {
|
|
|
|
var box = ctx.boxes[type] = {
|
|
|
|
channel: m.channel,
|
|
|
|
channel: m.channel,
|
|
|
|
type: type,
|
|
|
|
type: type,
|
|
|
@ -221,7 +229,8 @@ proxy.mailboxes = {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
box.queue.push(msg);
|
|
|
|
box.queue.push(msg);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data: m
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (!Crypto.Mailbox) {
|
|
|
|
if (!Crypto.Mailbox) {
|
|
|
|
return void console.error("chainpad-crypto is outdated and doesn't support mailboxes.");
|
|
|
|
return void console.error("chainpad-crypto is outdated and doesn't support mailboxes.");
|
|
|
@ -235,7 +244,7 @@ proxy.mailboxes = {
|
|
|
|
channel: m.channel,
|
|
|
|
channel: m.channel,
|
|
|
|
noChainPad: true,
|
|
|
|
noChainPad: true,
|
|
|
|
crypto: crypto,
|
|
|
|
crypto: crypto,
|
|
|
|
owners: [ctx.store.proxy.edPublic],
|
|
|
|
owners: opts.owners || [ctx.store.proxy.edPublic],
|
|
|
|
lastKnownHash: m.lastKnownHash
|
|
|
|
lastKnownHash: m.lastKnownHash
|
|
|
|
};
|
|
|
|
};
|
|
|
|
cfg.onConnectionChange = function () {}; // Allow reconnections in chainpad-netflux
|
|
|
|
cfg.onConnectionChange = function () {}; // Allow reconnections in chainpad-netflux
|
|
|
@ -357,7 +366,7 @@ proxy.mailboxes = {
|
|
|
|
// Continue
|
|
|
|
// Continue
|
|
|
|
onReady();
|
|
|
|
onReady();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
CpNetflux.start(cfg);
|
|
|
|
box.cpNf = CpNetflux.start(cfg);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var initializeHistory = function (ctx) {
|
|
|
|
var initializeHistory = function (ctx) {
|
|
|
@ -480,11 +489,15 @@ proxy.mailboxes = {
|
|
|
|
|
|
|
|
|
|
|
|
Object.keys(store.proxy.teams || {}).forEach(function (teamId) {
|
|
|
|
Object.keys(store.proxy.teams || {}).forEach(function (teamId) {
|
|
|
|
var team = store.proxy.teams[teamId];
|
|
|
|
var team = store.proxy.teams[teamId];
|
|
|
|
|
|
|
|
if (!team) { return; }
|
|
|
|
var teamMailbox = team.keys.mailbox || {};
|
|
|
|
var teamMailbox = team.keys.mailbox || {};
|
|
|
|
if (!teamMailbox.channel) { return; }
|
|
|
|
if (!teamMailbox.channel) { return; }
|
|
|
|
|
|
|
|
var opts = {
|
|
|
|
|
|
|
|
owners: [Util.find(team, ['keys', 'drive', 'edPublic'])]
|
|
|
|
|
|
|
|
};
|
|
|
|
openChannel(ctx, 'team-'+teamId, teamMailbox, function () {
|
|
|
|
openChannel(ctx, 'team-'+teamId, teamMailbox, function () {
|
|
|
|
//console.log('Mailbox team', teamId);
|
|
|
|
//console.log('Mailbox team', teamId);
|
|
|
|
});
|
|
|
|
}, opts);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
mailbox.post = function (box, type, content) {
|
|
|
|
mailbox.post = function (box, type, content) {
|
|
|
@ -497,9 +510,12 @@ proxy.mailboxes = {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
mailbox.open = function (key, m, cb, team) {
|
|
|
|
mailbox.open = function (key, m, cb, team, opts) {
|
|
|
|
if (TYPES.indexOf(key) === -1 && !team) { return; }
|
|
|
|
if (TYPES.indexOf(key) === -1 && !team) { return; }
|
|
|
|
openChannel(ctx, key, m, cb);
|
|
|
|
openChannel(ctx, key, m, cb, opts);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
mailbox.close = function (key, cb) {
|
|
|
|
|
|
|
|
leaveChannel(ctx, key, cb);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
mailbox.dismiss = function (data, cb) {
|
|
|
|
mailbox.dismiss = function (data, cb) {
|
|
|
|