Display OS notifications when receiving a notification on CryptPad

pull/1/head
yflory 5 years ago
parent d993827c7e
commit b84c4be69c

@ -1752,12 +1752,12 @@ define([
broadcast([], "UPDATE_METADATA");
},
pinPads: function (data, cb) { Store.pinPads(null, data, cb); },
}, waitFor, function (ev, data, clients) {
}, waitFor, function (ev, data, clients, cb) {
clients.forEach(function (cId) {
postMessage(cId, 'MAILBOX_EVENT', {
ev: ev,
data: data
});
}, cb);
});
});
};

@ -2,10 +2,11 @@ define([
'/common/common-util.js',
'/common/common-hash.js',
'/common/common-realtime.js',
'/common/notify.js',
'/common/outer/mailbox-handlers.js',
'/bower_components/chainpad-netflux/chainpad-netflux.js',
'/bower_components/chainpad-crypto/crypto.js',
], function (Util, Hash, Realtime, Handlers, CpNetflux, Crypto) {
], function (Util, Hash, Realtime, Notify, Handlers, CpNetflux, Crypto) {
var Mailbox = {};
var TYPES = [
@ -54,11 +55,11 @@ proxy.mailboxes = {
return (m.viewed || []).indexOf(hash) === -1 && hash !== m.lastKnownHash;
};
var showMessage = function (ctx, type, msg, cId) {
var showMessage = function (ctx, type, msg, cId, cb) {
ctx.emit('MESSAGE', {
type: type,
content: msg
}, cId ? [cId] : ctx.clients);
}, cId ? [cId] : ctx.clients, cb);
};
var hideMessage = function (ctx, type, hash, clients) {
ctx.emit('VIEWED', {
@ -272,7 +273,11 @@ proxy.mailboxes = {
});
}
box.content[hash] = msg;
showMessage(ctx, type, message);
showMessage(ctx, type, message, null, function (obj) {
if (!box.ready) { return; }
if (!obj || !obj.msg) { return; }
Notify.system(undefined, obj.msg);
});
});
} else {
// Message has already been viewed by the user
@ -320,6 +325,7 @@ proxy.mailboxes = {
view(n);
}
});
box.ready = true;
// Continue
onReady();
};

@ -124,10 +124,16 @@ define([
removeFromHistory(data.type, data.hash);
};
var onMessage = function (data) {
var onMessage = function (data, cb) {
// data = { type: 'type', content: {msg: 'msg', hash: 'hash'} }
console.log(data.type, data.content);
pushMessage(data);
if (data.content && typeof (data.content.getFormatText) == "function") {
var text = $('<div>').html(data.content.getFormatText()).text();
cb({
msg: text
});
}
if (!history[data.type]) { history[data.type] = []; }
history[data.type].push(data.content);
};
@ -224,7 +230,7 @@ define([
// CHANNEL WITH WORKER
sframeChan.on('EV_MAILBOX_EVENT', function (obj) {
sframeChan.on('EV_MAILBOX_EVENT', function (obj, cb) {
// obj = { ev: 'type', data: obj }
var ev = obj.ev;
var data = obj.data;
@ -232,7 +238,7 @@ define([
return void onHistory(data);
}
if (ev === 'MESSAGE') {
return void onMessage(data);
return void onMessage(data, cb);
}
if (ev === 'VIEWED') {
return void onViewed(data);

@ -414,8 +414,12 @@ define([
});
});
Cryptpad.mailbox.onEvent.reg(function (data) {
sframeChan.event('EV_MAILBOX_EVENT', data);
Cryptpad.mailbox.onEvent.reg(function (data, cb) {
sframeChan.query('EV_MAILBOX_EVENT', data, function (err, obj) {
if (!cb) { return; }
if (err) { return void cb({error: err}); }
cb(obj);
});
});
sframeChan.on('Q_MAILBOX_COMMAND', function (data, cb) {
Cryptpad.mailbox.execCommand(data, cb);

Loading…
Cancel
Save