WIP clientside components of private mailbox messages
This commit is contained in:
parent
dfae2908eb
commit
83d0b1ad30
@ -85,6 +85,9 @@ proxy.mailboxes = {
|
|||||||
if (!keys) { return void cb({error: "missing asymmetric encryption keys"}); }
|
if (!keys) { return void cb({error: "missing asymmetric encryption keys"}); }
|
||||||
if (!user || !user.channel || !user.curvePublic) { return void cb({error: "no notification channel"}); }
|
if (!user || !user.channel || !user.curvePublic) { return void cb({error: "no notification channel"}); }
|
||||||
|
|
||||||
|
var anonRpc = Util.find(ctx, [ 'store', 'anon_rpc', ]);
|
||||||
|
if (!anonRpc) { return void cb({error: "anonymous rpc session not ready"}); }
|
||||||
|
|
||||||
var crypto = Crypto.Mailbox.createEncryptor(keys);
|
var crypto = Crypto.Mailbox.createEncryptor(keys);
|
||||||
var network = ctx.store.network;
|
var network = ctx.store.network;
|
||||||
|
|
||||||
@ -94,29 +97,16 @@ proxy.mailboxes = {
|
|||||||
});
|
});
|
||||||
var ciphertext = crypto.encrypt(text, user.curvePublic);
|
var ciphertext = crypto.encrypt(text, user.curvePublic);
|
||||||
|
|
||||||
network.join(user.channel).then(function (wc) {
|
anonRpc.send("WRITE_PRIVATE_MESSAGE", [
|
||||||
wc.bcast(ciphertext).then(function () {
|
user.channel,
|
||||||
cb();
|
ciphertext
|
||||||
|
], function (err, response) {
|
||||||
// If we've just sent a message to one of our mailboxes, we have to trigger the handler manually
|
if (err) {
|
||||||
// (the server won't send back our message to us)
|
return void cb({
|
||||||
// If it isn't one of our mailboxes, we can close it now
|
error: err,
|
||||||
var box;
|
});
|
||||||
if (Object.keys(ctx.boxes).some(function (t) {
|
}
|
||||||
var _box = ctx.boxes[t];
|
return void cb();
|
||||||
if (_box.channel === user.channel) {
|
|
||||||
box = _box;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
})) {
|
|
||||||
var hash = ciphertext.slice(0, 64);
|
|
||||||
box.onMessage(text, null, null, null, hash, user.curvePublic);
|
|
||||||
} else {
|
|
||||||
wc.leave();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, function (err) {
|
|
||||||
cb({error: err});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user