|
|
@ -49,6 +49,12 @@ proxy.mailboxes = {
|
|
|
|
content: msg
|
|
|
|
content: msg
|
|
|
|
}, cId ? [cId] : ctx.clients);
|
|
|
|
}, cId ? [cId] : ctx.clients);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
var hideMessage = function (ctx, type, hash, clients) {
|
|
|
|
|
|
|
|
ctx.emit('VIEWED', {
|
|
|
|
|
|
|
|
type: type,
|
|
|
|
|
|
|
|
hash: hash
|
|
|
|
|
|
|
|
}, clients || ctx.clients);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var getMyKeys = function (ctx) {
|
|
|
|
var getMyKeys = function (ctx) {
|
|
|
|
var proxy = ctx.store && ctx.store.proxy;
|
|
|
|
var proxy = ctx.store && ctx.store.proxy;
|
|
|
@ -86,14 +92,6 @@ proxy.mailboxes = {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var updateLastKnownHash = function (ctx, type) {
|
|
|
|
|
|
|
|
var m = Util.find(ctx, ['store', 'proxy', 'mailboxes', type]);
|
|
|
|
|
|
|
|
if (!m) { return; }
|
|
|
|
|
|
|
|
var box = ctx.boxes[type];
|
|
|
|
|
|
|
|
if (!box) { return; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Mark a message as read
|
|
|
|
// Mark a message as read
|
|
|
|
var dismiss = function (ctx, data, cId, cb) {
|
|
|
|
var dismiss = function (ctx, data, cId, cb) {
|
|
|
|
var type = data.type;
|
|
|
|
var type = data.type;
|
|
|
@ -116,7 +114,6 @@ proxy.mailboxes = {
|
|
|
|
if (idx === 0) {
|
|
|
|
if (idx === 0) {
|
|
|
|
m.lastKnownHash = hash;
|
|
|
|
m.lastKnownHash = hash;
|
|
|
|
box.history.shift();
|
|
|
|
box.history.shift();
|
|
|
|
delete box.content[hash];
|
|
|
|
|
|
|
|
} else if (m.viewed.indexOf(hash) === -1) {
|
|
|
|
} else if (m.viewed.indexOf(hash) === -1) {
|
|
|
|
m.viewed.push(hash);
|
|
|
|
m.viewed.push(hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -145,16 +142,14 @@ proxy.mailboxes = {
|
|
|
|
// Make sure we remove data about dismissed messages
|
|
|
|
// Make sure we remove data about dismissed messages
|
|
|
|
Object.keys(box.content).forEach(function (h) {
|
|
|
|
Object.keys(box.content).forEach(function (h) {
|
|
|
|
if (box.history.indexOf(h) === -1 || m.viewed.indexOf(h) !== -1) {
|
|
|
|
if (box.history.indexOf(h) === -1 || m.viewed.indexOf(h) !== -1) {
|
|
|
|
|
|
|
|
Handlers.remove(ctx, box, box.content[h], h);
|
|
|
|
delete box.content[h];
|
|
|
|
delete box.content[h];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Realtime.whenRealtimeSyncs(ctx.store.realtime, function () {
|
|
|
|
Realtime.whenRealtimeSyncs(ctx.store.realtime, function () {
|
|
|
|
cb();
|
|
|
|
cb();
|
|
|
|
ctx.emit('VIEWED', {
|
|
|
|
hideMessage(ctx, type, hash, ctx.clients.filter(function (clientId) {
|
|
|
|
type: type,
|
|
|
|
|
|
|
|
hash: hash
|
|
|
|
|
|
|
|
}, ctx.clients.filter(function (clientId) {
|
|
|
|
|
|
|
|
return clientId !== cId;
|
|
|
|
return clientId !== cId;
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -201,19 +196,23 @@ proxy.mailboxes = {
|
|
|
|
cfg.onConnect = function (wc, sendMessage) {
|
|
|
|
cfg.onConnect = function (wc, sendMessage) {
|
|
|
|
// Send a message to our box?
|
|
|
|
// Send a message to our box?
|
|
|
|
// NOTE: we use our own curvePublic so that we can decrypt our own message :)
|
|
|
|
// NOTE: we use our own curvePublic so that we can decrypt our own message :)
|
|
|
|
box.sendMessage = function (_msg) {
|
|
|
|
box.sendMessage = function (_msg, cb) {
|
|
|
|
|
|
|
|
cb = cb || function () {};
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
msg = JSON.stringify(_msg);
|
|
|
|
msg = JSON.stringify(_msg);
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sendMessage(msg, function (err, hash) {
|
|
|
|
sendMessage(msg, function (err, hash) {
|
|
|
|
|
|
|
|
if (err) { return void console.error(err); }
|
|
|
|
|
|
|
|
box.history.push(hash);
|
|
|
|
box.content[hash] = _msg;
|
|
|
|
box.content[hash] = _msg;
|
|
|
|
var message = {
|
|
|
|
var message = {
|
|
|
|
msg: _msg,
|
|
|
|
msg: _msg,
|
|
|
|
hash: hash
|
|
|
|
hash: hash
|
|
|
|
};
|
|
|
|
};
|
|
|
|
showMessage(ctx, type, message);
|
|
|
|
showMessage(ctx, type, message);
|
|
|
|
|
|
|
|
cb();
|
|
|
|
}, keys.curvePublic);
|
|
|
|
}, keys.curvePublic);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
box.queue.forEach(function (msg) {
|
|
|
|
box.queue.forEach(function (msg) {
|
|
|
@ -236,7 +235,7 @@ proxy.mailboxes = {
|
|
|
|
msg: msg,
|
|
|
|
msg: msg,
|
|
|
|
hash: hash
|
|
|
|
hash: hash
|
|
|
|
};
|
|
|
|
};
|
|
|
|
Handlers(ctx, box, message, function (toDismiss) {
|
|
|
|
Handlers.add(ctx, box, message, function (toDismiss) {
|
|
|
|
if (toDismiss) {
|
|
|
|
if (toDismiss) {
|
|
|
|
dismiss(ctx, {
|
|
|
|
dismiss(ctx, {
|
|
|
|
type: type,
|
|
|
|
type: type,
|
|
|
@ -275,11 +274,9 @@ proxy.mailboxes = {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Listen for changes in the "viewed" and lastKnownHash values
|
|
|
|
// Listen for changes in the "viewed" and lastKnownHash values
|
|
|
|
var view = function (h) {
|
|
|
|
var view = function (h) {
|
|
|
|
|
|
|
|
Handlers.remove(ctx, box, box.content[h], h);
|
|
|
|
delete box.content[h];
|
|
|
|
delete box.content[h];
|
|
|
|
ctx.emit('VIEWED', {
|
|
|
|
hideMessage(ctx, type, h);
|
|
|
|
type: type,
|
|
|
|
|
|
|
|
hash: h
|
|
|
|
|
|
|
|
}, ctx.clients);
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
ctx.store.proxy.on('change', ['mailboxes', type], function (o, n, p) {
|
|
|
|
ctx.store.proxy.on('change', ['mailboxes', type], function (o, n, p) {
|
|
|
|
if (p[2] === 'lastKnownHash') {
|
|
|
|
if (p[2] === 'lastKnownHash') {
|
|
|
@ -350,7 +347,6 @@ proxy.mailboxes = {
|
|
|
|
|
|
|
|
|
|
|
|
if (BLOCKING_TYPES.indexOf(key) === -1) {
|
|
|
|
if (BLOCKING_TYPES.indexOf(key) === -1) {
|
|
|
|
openChannel(ctx, key, m, function () {
|
|
|
|
openChannel(ctx, key, m, function () {
|
|
|
|
updateLastKnownHash(ctx, key);
|
|
|
|
|
|
|
|
//console.log(key + ' mailbox is ready');
|
|
|
|
//console.log(key + ' mailbox is ready');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|