<link rel="manifest" href="/manifest.json" />
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
<script>
  var OneSignal = window.OneSignal || [];
  OneSignal.push(function() {
    OneSignal.init({
      appId: "{{ONE_SIGNAL_APPID}}",
    });
  });

  OneSignal.push(function() {
     OneSignal.on('subscriptionChange', function (isSubscribed) {
     console.log("The user's subscription state is now:",isSubscribed);

     OneSignal.push(function() {
          OneSignal.sendTag("device_id", "device-{{device_id}}");
     });

    });
 });

  OneSignal.push(function() {
    OneSignal.isPushNotificationsEnabled(function(isEnabled) {
          OneSignal.getUserId(function(userId) {
              console.log("OneSignal User ID:", userId);
              $.get({ 
              url: "{% url 'onesignal:update-uuid' %}",
              data: {
              device_id : {{device_id}},
              onesignal_id: userId, 
              }});
          });
    });
 });

  OneSignal.push(function() {
    OneSignal.on('notificationDisplay', function (event) {
    	console.log('OneSignal notification displayed:', event.data);
        if(event.data != undefined) {
            if(event.data['cmd'] == 'RELOAD-UI') {
                location.reload();
            }
        }
    });
  });

</script>





