<commit_before><!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Queue</title>
    <!-- Firebase App (the core Firebase SDK) must be listed first -->
    <script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-app.js"></script>
    <!-- Firebase Authentication -->
    <script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-auth.js"></script>
    <!-- Firebase Messaging -->
    <script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-messaging.js"></script>

    <link rel="stylesheet" href="studentQueue.css">
    <link rel="stylesheet" href="/style/common.css">
    <script src="/script/auth.js"></script>
    
    <!--Font-->
    <link href='https://fonts.googleapis.com/css?family=Noto+Sans:400,700,400italic,700italic&subset=latin,latin-ext' rel='stylesheet' type='text/css'></link>
  </head>

  <script>
    let studentToken;
    let iidToken;
    let notifyBool = true; 
    const SERVER_KEY = "<KEY>";
    const VAPID_KEY = "<KEY>";

    //Retrieve Firebase Messaging object 
    const messaging = firebase.messaging();
    messaging.usePublicVapidKey(VAPID_KEY);
    
    //Ask user for permission to send notifications
    messaging
      .requestPermission()
      .then(function () {
        console.log("Notification permission granted.");
            
        // get the token in the form of promise
        return messaging.getToken();
      })
      .then(function(token) {
        iidToken = token;
      })
      .catch(function (err) {
        console.log("Unable to get permission to notify.", err);
      });

    //If user on page, no notification sent
    messaging.onMessage(function(payload) {
      console.log("User on page- message received. ", payload);
    });

    function getToken() {
      //Initialize user's Firebase token
      var user = firebase.auth().currentUser;
      firebase.auth().onAuthStateChanged(function(user) {
        if (user) {
          console.log("User is signed in");
          user.getIdToken().then((token) => setToken(token));
        } 
        // Redirect to home page if not logged in
        else {
          console.log("User is not logged in");
          window.location.href = "/";
        }
      }); 
    }

    function setToken(token){
      studentToken = token;
      makeRequest();
    }

    let gotWorkspaceID = false;

    let repeat = setInterval(makeRequest, 10000);
    function makeRequest(){
      var params = window.location.search + "&studentToken=" + studentToken;
      const request = new Request("/check-student" + params, {method: "GET"});
      fetch(request).then(response => response.json()).then((studentPosition) => {
        if (studentPosition.position === 0) {
          document.getElementById("queue_status").innerText = "";
          getTA();

          if (notifyBool) {
            sendNotification();
            notifyBool = false;
          }    
        } else {
            document.getElementById("studentPosition").innerText = "You are #" + studentPosition.position + " on the queue.";
            
            document.getElementById("workspaceRedirect").href = studentPosition.workspace;
            document.getElementById("workspaceRedirect").innerText = "go to workspace";
        }
      });
    }

    function getTA(){
      var params = window.location.search + "&studentToken=" + studentToken;
      const request = new Request("/get-ta" + params, {method: "GET"});

      fetch(request).then(response => response.json()).then((helpedBy) => {
        if (helpedBy == "null"){
            document.getElementById("beingHelped").innerText = "You are done being helped.";
            document.getElementById("workspaceRedirect").href = "";
            document.getElementById("workspaceRedirect").innerText = "";
            gotWorkspaceID = false;
            clearInterval(repeat);

        } else {
            document.getElementById("beingHelped").innerText = "You are being helped by " + helpedBy;
        }
      });
    }

    function sendNotification(){
      var key = SERVER_KEY; 
      var to = iidToken; 
      var notification = {
        'title': 'you were just taken off the queue!',
        'body': 'navigate back to get the workspace link',
      };

      fetch('https://fcm.googleapis.com/fcm/send', {
      'method': 'POST',
      'headers': {
        'Authorization': 'key=' + key,
        'Content-Type': 'application/json'
      },
      'body': JSON.stringify({
        'notification': notification,
        'to': to
      })
      }).then(function(response) {
        console.log(response);
      }).catch(function(error) {
        console.error(error);
      })
    }
  </script>

  <body onload="getToken()">
    <div class="top-right-buttons">
      <button class="reg-button" onclick="signOut()">Log Out</button>
    </div>

    <div class = "wrapper">
      <h1 id = "beingHelped"> </h1>
    </div>

    <div id="queue_status"  class="wrapper">
      <h1 id="studentPosition"></h1>
      <a href="" id = "workspaceRedirect" style="text-decoration: none;" rel="noopener noreferrer" target="_blank"></a>
    </div>
  </body>

</html><commit_msg>Fix workspace link so that id doesn't dissapear.<commit_after><!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Queue</title>
    <!-- Firebase App (the core Firebase SDK) must be listed first -->
    <script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-app.js"></script>
    <!-- Firebase Authentication -->
    <script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-auth.js"></script>
    <!-- Firebase Messaging -->
    <script src="https://www.gstatic.com/firebasejs/7.15.1/firebase-messaging.js"></script>

    <link rel="stylesheet" href="studentQueue.css">
    <link rel="stylesheet" href="/style/common.css">
    <script src="/script/auth.js"></script>
    
    <!--Font-->
    <link href='https://fonts.googleapis.com/css?family=Noto+Sans:400,700,400italic,700italic&subset=latin,latin-ext' rel='stylesheet' type='text/css'></link>
  </head>

  <script>
    let studentToken;
    let iidToken;
    let notifyBool = true; 
    const SERVER_KEY = "<KEY>";
    const VAPID_KEY = "<KEY>";

    //Retrieve Firebase Messaging object 
    const messaging = firebase.messaging();
    messaging.usePublicVapidKey(VAPID_KEY);
    
    //Ask user for permission to send notifications
    messaging
      .requestPermission()
      .then(function () {
        console.log("Notification permission granted.");
            
        // get the token in the form of promise
        return messaging.getToken();
      })
      .then(function(token) {
        iidToken = token;
      })
      .catch(function (err) {
        console.log("Unable to get permission to notify.", err);
      });

    //If user on page, no notification sent
    messaging.onMessage(function(payload) {
      console.log("User on page- message received. ", payload);
    });

    function getToken() {
      //Initialize user's Firebase token
      var user = firebase.auth().currentUser;
      firebase.auth().onAuthStateChanged(function(user) {
        if (user) {
          console.log("User is signed in");
          user.getIdToken().then((token) => setToken(token));
        } 
        // Redirect to home page if not logged in
        else {
          console.log("User is not logged in");
          window.location.href = "/";
        }
      }); 
    }

    function setToken(token){
      studentToken = token;
      makeRequest();
    }

    let gotWorkspaceID = false;

    let repeat = setInterval(makeRequest, 10000);
    function makeRequest(){
      var params = window.location.search + "&studentToken=" + studentToken;
      const request = new Request("/check-student" + params, {method: "GET"});
      fetch(request).then(response => response.json()).then((studentPosition) => {
        if (studentPosition.position === 0) {
          document.getElementById("queue_status").innerText = "";
          getTA();

          if (notifyBool) {
            sendNotification();
            notifyBool = false;
          }    
        } else {
            document.getElementById("studentPosition").innerText = "You are #" + studentPosition.position + " on the queue.";
            
            document.getElementById("workspaceRedirect").href = studentPosition.workspace;
            document.getElementById("workspaceRedirect").innerText = "go to workspace";
        }
      });
    }

    function getTA(){
      var params = window.location.search + "&studentToken=" + studentToken;
      const request = new Request("/get-ta" + params, {method: "GET"});

      fetch(request).then(response => response.json()).then((helpedBy) => {
        if (helpedBy == "null"){
            document.getElementById("beingHelped").innerText = "You are done being helped.";
            document.getElementById("workspaceRedirect").href = "";
            document.getElementById("workspaceRedirect").innerText = "";
            gotWorkspaceID = false;
            clearInterval(repeat);

        } else {
            document.getElementById("beingHelped").innerText = "You are being helped by " + helpedBy;
        }
      });
    }

    function sendNotification(){
      var key = SERVER_KEY; 
      var to = iidToken; 
      var notification = {
        'title': 'you were just taken off the queue!',
        'body': 'navigate back to get the workspace link',
      };

      fetch('https://fcm.googleapis.com/fcm/send', {
      'method': 'POST',
      'headers': {
        'Authorization': 'key=' + key,
        'Content-Type': 'application/json'
      },
      'body': JSON.stringify({
        'notification': notification,
        'to': to
      })
      }).then(function(response) {
        console.log(response);
      }).catch(function(error) {
        console.error(error);
      })
    }
  </script>

  <body onload="getToken()">
    <div class="top-right-buttons">
      <button class="reg-button" onclick="signOut()">Log Out</button>
    </div>

    <div class = "wrapper">
      <h1 id = "beingHelped"> </h1>
    </div>

    <div id="queue_status"  class="wrapper">
      <h1 id="studentPosition"></h1>
    </div>

    <div class="wrapper">
      <a href="" id = "workspaceRedirect" style="text-decoration: none;" rel="noopener noreferrer" target="_blank"></a>
    </div>
  </body>

</html>
{'fraction_non_alphanumeric': 0.15164686564280885, 'fraction_numerical': 0.0067613252197430695, 'mean_word_length': 2.467515070328198, 'pattern_counts': {'":': 0, '<': 93, '<?xml version=': 0, '>': 103, 'https://': 10, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3204220', 'n_tokens_mistral': 3041, 'n_tokens_neox': 2922, 'n_words': 639}