Test sending a message to a friend
This commit is contained in:
parent
b15c67e8d4
commit
9ead40a332
@ -625,11 +625,25 @@ define([
|
|||||||
|
|
||||||
// Set the display name (username) in the proxy
|
// Set the display name (username) in the proxy
|
||||||
Store.setDisplayName = function (clientId, value, cb) {
|
Store.setDisplayName = function (clientId, value, cb) {
|
||||||
if (store.mailbox) {
|
if (store.mailbox && store.proxy.friends) {
|
||||||
// XXX test mailbox, should be removed in prod
|
// XXX test mailbox, should be removed in prod
|
||||||
store.mailbox.post('notifications', 'NAME_CHANGED', {
|
/*store.mailbox.post('notifications', 'NAME_CHANGED', {
|
||||||
old: store.proxy[Constants.displayNameKey],
|
old: store.proxy[Constants.displayNameKey],
|
||||||
new: value
|
new: value
|
||||||
|
});*/
|
||||||
|
Object.keys(store.proxy.friends).forEach(function (curve) {
|
||||||
|
var f = store.proxy.friends[curve];
|
||||||
|
if (!f.notifications) { return; }
|
||||||
|
store.mailbox.sendTo('NAME_CHANGED', {
|
||||||
|
old: store.proxy[Constants.displayNameKey],
|
||||||
|
new: value
|
||||||
|
}, {
|
||||||
|
channel: f.notifications,
|
||||||
|
curvePublic: curve
|
||||||
|
}, function (obj) {
|
||||||
|
if (obj && obj.error) { return void console.error(obj.error); }
|
||||||
|
console.log('notif sent to '+f);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
store.proxy[Constants.displayNameKey] = value;
|
store.proxy[Constants.displayNameKey] = value;
|
||||||
|
|||||||
@ -55,12 +55,6 @@ proxy.mailboxes = {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var getContact = function (ctx, user) {
|
|
||||||
var proxy = ctx.store && ctx.store.proxy;
|
|
||||||
if (!proxy.friends || !proxy.friends[user]) { return; }
|
|
||||||
return proxy.friends[user];
|
|
||||||
};
|
|
||||||
|
|
||||||
var openChannel = function (ctx, type, m, onReady) {
|
var openChannel = function (ctx, type, m, onReady) {
|
||||||
var box = ctx.boxes[type] = {
|
var box = ctx.boxes[type] = {
|
||||||
queue: [], // Store the messages to send when the channel is ready
|
queue: [], // Store the messages to send when the channel is ready
|
||||||
@ -158,6 +152,11 @@ proxy.mailboxes = {
|
|||||||
for (var i = toClean.length-1; i>=0; i--) {
|
for (var i = toClean.length-1; i>=0; i--) {
|
||||||
m.viewed.splice(toClean[i], 1);
|
m.viewed.splice(toClean[i], 1);
|
||||||
}
|
}
|
||||||
|
// Listen for changes in the "viewed" and lastKnownHash values
|
||||||
|
ctx.store.proxy.on('change', ['mailboxes', type], function () {
|
||||||
|
// Check everything!
|
||||||
|
// XXX
|
||||||
|
});
|
||||||
// Continue
|
// Continue
|
||||||
onReady();
|
onReady();
|
||||||
};
|
};
|
||||||
@ -171,8 +170,7 @@ proxy.mailboxes = {
|
|||||||
}
|
}
|
||||||
var keys = getMyKeys(ctx);
|
var keys = getMyKeys(ctx);
|
||||||
if (!keys) { return void cb({error: "missing asymmetric encryption keys"}); }
|
if (!keys) { return void cb({error: "missing asymmetric encryption keys"}); }
|
||||||
var friend = getContact(ctx, user);
|
if (!user || !user.channel || !user.curvePublic) { return void cb({error: "no notification channel"}); }
|
||||||
if (!friend || !friend.notifications) { return void cb({error: "no notification channel"}); }
|
|
||||||
|
|
||||||
var crypto = Crypto.Mailbox.createEncryptor(keys);
|
var crypto = Crypto.Mailbox.createEncryptor(keys);
|
||||||
var network = ctx.store.network;
|
var network = ctx.store.network;
|
||||||
@ -180,9 +178,9 @@ proxy.mailboxes = {
|
|||||||
var ciphertext = crypto.encrypt(JSON.stringify({
|
var ciphertext = crypto.encrypt(JSON.stringify({
|
||||||
type: type,
|
type: type,
|
||||||
content: msg
|
content: msg
|
||||||
}), friend.curvePublic);
|
}), user.curvePublic);
|
||||||
|
|
||||||
network.join(friend.notification).then(function (wc) {
|
network.join(user.channel).then(function (wc) {
|
||||||
wc.bcast(ciphertext).then(function () {
|
wc.bcast(ciphertext).then(function () {
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
@ -256,6 +254,12 @@ proxy.mailboxes = {
|
|||||||
|
|
||||||
Realtime.whenRealtimeSyncs(ctx.store.realtime, function () {
|
Realtime.whenRealtimeSyncs(ctx.store.realtime, function () {
|
||||||
cb();
|
cb();
|
||||||
|
ctx.emit('VIEWED', {
|
||||||
|
type: type,
|
||||||
|
hash: hash
|
||||||
|
}, ctx.clients.filter(function (clientId) {
|
||||||
|
return clientId !== cId;
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user