Test notification prompt

pull/1/head
yflory 4 years ago
parent b7b8ea1c64
commit 3468bb33a2

@ -569,6 +569,7 @@ define([
isPresent: parsed.hashData && parsed.hashData.present, isPresent: parsed.hashData && parsed.hashData.present,
isEmbed: parsed.hashData && parsed.hashData.embed, isEmbed: parsed.hashData && parsed.hashData.embed,
isHistoryVersion: parsed.hashData && parsed.hashData.versionHash, isHistoryVersion: parsed.hashData && parsed.hashData.versionHash,
notifications: Notification && Notification.permission === "granted",
accounts: { accounts: {
donateURL: Cryptpad.donateURL, donateURL: Cryptpad.donateURL,
upgradeURL: Cryptpad.upgradeURL upgradeURL: Cryptpad.upgradeURL
@ -1569,9 +1570,13 @@ define([
}); });
}); });
if (cfg.messaging) { sframeChan.on('Q_ASK_NOTIFICATION', function (data, cb) {
Notifier.getPermission(); Notification.requestPermission(function (s) {
cb(s === "granted");
});
});
if (cfg.messaging) {
sframeChan.on('Q_CHAT_OPENPADCHAT', function (data, cb) { sframeChan.on('Q_CHAT_OPENPADCHAT', function (data, cb) {
Cryptpad.universal.execCommand({ Cryptpad.universal.execCommand({
type: 'messenger', type: 'messenger',

@ -990,6 +990,28 @@ MessengerUI, Messages) {
h('div.cp-notifications-empty', Messages.notifications_empty) h('div.cp-notifications-empty', Messages.notifications_empty)
]); ]);
var pads_options = [div]; 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()) { if (Common.isLoggedIn()) {
pads_options.unshift(h("hr")); pads_options.unshift(h("hr"));
pads_options.unshift(openNotifsApp); pads_options.unshift(openNotifsApp);

Loading…
Cancel
Save