From 3468bb33a2b7bfa0740072bdd640045f35846619 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 12 Nov 2020 11:22:46 +0100 Subject: [PATCH] Test notification prompt --- www/common/sframe-common-outer.js | 9 +++++++-- www/common/toolbar.js | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index ad128db33..d17924cf0 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -569,6 +569,7 @@ define([ isPresent: parsed.hashData && parsed.hashData.present, isEmbed: parsed.hashData && parsed.hashData.embed, isHistoryVersion: parsed.hashData && parsed.hashData.versionHash, + notifications: Notification && Notification.permission === "granted", accounts: { donateURL: Cryptpad.donateURL, upgradeURL: Cryptpad.upgradeURL @@ -1569,9 +1570,13 @@ define([ }); }); - if (cfg.messaging) { - Notifier.getPermission(); + sframeChan.on('Q_ASK_NOTIFICATION', function (data, cb) { + Notification.requestPermission(function (s) { + cb(s === "granted"); + }); + }); + if (cfg.messaging) { sframeChan.on('Q_CHAT_OPENPADCHAT', function (data, cb) { Cryptpad.universal.execCommand({ type: 'messenger', diff --git a/www/common/toolbar.js b/www/common/toolbar.js index 78e4e91f3..709d659b5 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -990,6 +990,28 @@ MessengerUI, Messages) { h('div.cp-notifications-empty', Messages.notifications_empty) ]); var pads_options = [div]; + + var metadataMgr = config.metadataMgr; + var privateData = metadataMgr.getPrivateData(); + if (!privateData.notifications) { + Messages.allowNotifications = "Allow notifications"; // XXX + var allowNotif = h('div.cp-notifications-gotoapp', h('p', Messages.allowNotifications)); + pads_options.unshift(h("hr")); + pads_options.unshift(allowNotif); + var $allow = $(allowNotif).click(function () { + Common.getSframeChannel().event('Q_ASK_NOTIFICATION', null, function (granted) { + if (!granted) { return; } + $(allowNotif).remove(); + }); + }); + metadataMgr.onChange(function () { + var privateData = metadataMgr.getPrivateData(); + if (!privateData.notifications) { return; } + $allow.remove(); + }); + } + + if (Common.isLoggedIn()) { pads_options.unshift(h("hr")); pads_options.unshift(openNotifsApp);