<script>
          var originalTitle = document.title;
          $(function() {
                    $.ajax({ url: "/api/discourse/notifications/{{current_user.name}}/count"
                           , success: function(data) {
                              updateNotificationsPill(data);
                    }});
          });
          
          (function poll() {
                    setTimeout(function() {
                              $.ajax({ url: "/api/discourse/notifications/{{current_user.name}}/count"
                                     , success: function(data) {
                                        updateNotificationsPill(data);
                                      }, dataType: "json", complete: poll });
                    }, 15000);
           })();
          
          function updateNotificationsPill(data) {
                    if (data !== 0 && $.isNumeric(data)) {
                              $('#community-nav').html('Community <span class="badge badge-danger">' + data + '</span>')
                              document.title = '(' + data + ') ' + originalTitle;
                    } else {
                              $('#community-nav').html('Community')
                              document.title = originalTitle
                    }
          }
</script>
<script>
          var originalTitle = document.title;
          $(function() {
                    $.ajax({ url: "/api/discourse/notifications/{{current_user.name}}/count"
                           , success: function(data) {
                              updateNotificationsPill(data);
                    }, error: function(){ //Create a new user
                              $.ajax('/api/discourse/user/{{current_user.name}}/create');
                              }
                              });
          });
          
          (function poll() {
                    setTimeout(function() {
                              $.ajax({ url: "/api/discourse/notifications/{{current_user.name}}/count"
                                     , success: function(data) {
                                        updateNotificationsPill(data);
                                      }, dataType: "json", complete: poll });
                    }, 15000);
           })();
          
          function updateNotificationsPill(data) {
                    if (data !== 0 && $.isNumeric(data)) {
                              $('#community-nav').html('Community <span class="badge badge-danger">' + data + '</span>')
                              document.title = '(' + data + ') ' + originalTitle;
                    } else {
                              $('#community-nav').html('Community')
                              document.title = originalTitle
                    }
          }
</script>
Add API call to create discourse user
Add API call to create discourse user
