From 7fd3bba2a64c07fbaadc239d5ab18a7965b6ae5f Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 17 May 2019 17:42:33 +0200 Subject: [PATCH] Test sending a message from a pad (inner iframe) --- www/common/outer/async-store.js | 1 + www/common/outer/mailbox.js | 3 +++ www/common/sframe-common-mailbox.js | 10 +++++++++- www/common/sframe-common-title.js | 18 +++++++++++++++++- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 035fabda4..5b25b0379 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -451,6 +451,7 @@ define([ avatar: Util.find(store.proxy, ['profile', 'avatar']), profile: Util.find(store.proxy, ['profile', 'view']), color: getUserColor(), + notifications: Util.find(store.proxy, ['mailboxes', 'notifications', 'channel']), curvePublic: store.proxy.curvePublic, }, // "priv" is not shared with other users but is needed by the apps diff --git a/www/common/outer/mailbox.js b/www/common/outer/mailbox.js index 4ed0868ca..2f5d84c00 100644 --- a/www/common/outer/mailbox.js +++ b/www/common/outer/mailbox.js @@ -343,6 +343,9 @@ proxy.mailboxes = { if (cmd === 'DISMISS') { return void dismiss(ctx, data, clientId, cb); } + if (cmd === 'SENDTO') { + return void sendTo(ctx, data.type, data.msg, data.user, cb); + } }; return mailbox; diff --git a/www/common/sframe-common-mailbox.js b/www/common/sframe-common-mailbox.js index c9f0625cf..6179f55d8 100644 --- a/www/common/sframe-common-mailbox.js +++ b/www/common/sframe-common-mailbox.js @@ -31,8 +31,16 @@ define([ }); }; - mailbox.sendTo = function (user, type, content) { + mailbox.sendTo = function (type, content, user) { console.log(user, type, content); + execCommand('SENDTO', { + type: type, + msg: content, + user: user + }, function (err, obj) { + if (err || (obj && obj.error)) { return void console.error(err || obj.error); } + console.log('notif sent to other user from inner'); + }); }; // UI diff --git a/www/common/sframe-common-title.js b/www/common/sframe-common-title.js index 3e98b853e..d204f5268 100644 --- a/www/common/sframe-common-title.js +++ b/www/common/sframe-common-title.js @@ -69,7 +69,23 @@ define([ return void UI.alert(Messages.pinLimitNotPinned, null, true); } else if (err) { return; } evTitleChange.fire(title); - if (titleUpdated) { titleUpdated(undefined, title); } + if (titleUpdated) { + titleUpdated(undefined, title); + // XXX Test notifications from inner + var users = metadataMgr.getMetadata().users; + var me = metadataMgr.getNetfluxId(); + Object.keys(users).forEach(function (netfluxId) { + if (netfluxId === me) { return; } + var user = users[netfluxId]; + if (!user.curvePublic || !user.notifications) { return; } + Common.mailbox.sendTo("TEST_NOTIF_TITLE", { + new_title: title + }, { + channel: user.notifications, + curvePublic: user.curvePublic + }); + }); + } }); });