Skip to content

Commit

Permalink
Fixed notification permission prompt (publiclab#6003)
Browse files Browse the repository at this point in the history
* Fixed notification permission prompt

* Minor Change

* Moved notification prompt code from application.js to cable.js
  • Loading branch information
namangupta01 authored and enviro3 committed Aug 12, 2019
1 parent 2239ead commit 26d9649
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@
//= require header_footer.js
//= require keybindings.js
//= require realtime_username_validation.js
//= require cable.js
//= require cable.js
8 changes: 8 additions & 0 deletions app/assets/javascripts/cable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@
App.cable = ActionCable.createConsumer();

}).call(this);

// To get notification permission
Notification.requestPermission().then(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
console.log("Permission Granted");
}
});
9 changes: 0 additions & 9 deletions app/assets/javascripts/channels/user_notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,12 @@ App.room = App.cable.subscriptions.create('UserNotificationChannel',{
}
// Let's check whether notification permissions have already been granted
else if (Notification.permission === "granted") {
console.log(notification);
// If it's okay let's create a notification
var notification = new Notification(data.notification.title, data.notification.option);
notification.onclick = function(event) {
event.preventDefault(); // prevent the browser from focusing the Notification's tab
window.open(data.notification.path, '_blank');
}
}
else if (Notification.permission == "denied") {
Notification.requestPermission().then(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
new Notification(notification.title, notification.option);
}
});
}
}
});

0 comments on commit 26d9649

Please sign in to comment.