From 87bccb1204a33685cde2cb32317341bac966e161 Mon Sep 17 00:00:00 2001 From: Leonardo Crauss Daronco Date: Fri, 9 Dec 2016 15:18:41 -0200 Subject: [PATCH] Require browser notification permissions only when the user signs in The only notification right now is for signed in users that are viewing their room's page, so request permission only in this case. --- app/assets/javascripts/shared.js.erb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/shared.js.erb b/app/assets/javascripts/shared.js.erb index 95f00343..dba6461e 100644 --- a/app/assets/javascripts/shared.js.erb +++ b/app/assets/javascripts/shared.js.erb @@ -68,5 +68,10 @@ var showNotification = function(title, options) { } }; -// TODO: only need permissions if the user is signed in -Notification.requestPermission(); +// For now there are notifications only for users signed in and when they +// are in their room's page +$(document).on("turbolinks:load", function() { + if (GreenLight.user.roomOwner) { + Notification.requestPermission(); + } +});