function databaseQuery() {

      userBase = firebase.database().ref("users/");
      userFriends = firebase.database().ref("users/" + user.uid + "/friends");
      userInvites = firebase.database().ref("users/" + user.uid + "/invites");

      var fetchData = function (postRef) {
          postRef.on('child_added', function (data) {
              onlineInt = 1;

              var i = findUIDItemInArr(data.key, userArr);
              if(userArr[i] != data.val() && i != -1){
                  //console.log("Adding " + userArr[i].userName + " to most updated version: " + data.val().userName);
                  userArr[i] = data.val();
              }

              if(data.key == user.uid){
                  user = data.val();
                  console.log("User Updated: 1");
              }
          });

          postRef.on('child_changed', function (data) {
              var i = findUIDItemInArr(data.key, userArr);
              if(userArr[i] != data.val() && i != -1){
                  console.log("Updating " + userArr[i].userName + " to most updated version: " + data.val().userName);
                  userArr[i] = data.val();

                  if(friendArr.includes(data.key)){
                      changeFriendElement(friendArr[friendArr.indexOf(data.key)]);
                  }
              }

              if(data.key == user.uid){
                  user = data.val();
                  console.log("User Updated: 2");
              }
          });

          postRef.on('child_removed', function (data) {
              var i = findUIDItemInArr(data.key, userArr);
              if(userArr[i] != data.val() && i != -1){
                  console.log("Removing " + userArr[i].userName + " / " + data.val().userName);
                  userArr.splice(i, 1);
              }
          });
      };

      var fetchFriends = function (postRef) {
          postRef.on('child_added', function (data) {
              friendArr.push(data.val());

              createFriendElement(data.val());
          });

          postRef.on('child_changed', function (data) {
              console.log(friendArr);
              friendArr[data.key] = data.val();
              console.log(friendArr);

              changeFriendElement(data.val());
          });

          postRef.on('child_removed', function (data) {
              sessionStorage.setItem("validUser", JSON.stringify(user));
              location.reload();
          });
      };

      var fetchInvites = function (postRef) {
          postRef.on('child_added', function (data) {
              inviteArr.push(data.val());

              inviteNote.style.background = "#ff3923";
          });

          postRef.on('child_changed', function (data) {
              console.log(inviteArr);
              inviteArr[data.key] = data.val();
              console.log(inviteArr);
          });

          postRef.on('child_removed', function (data) {
              console.log(inviteArr);
              inviteArr.splice(data.key, 1);
              console.log(inviteArr);

              if (inviteArr.length == 0) {
                  console.log("Invite List Removed");
                  inviteNote.style.background = "#008222";
              }
          });
      };

      fetchData(userBase);
      fetchFriends(userFriends);
      fetchInvites(userInvites);

      listeningFirebaseRefs.push(userBase);
      listeningFirebaseRefs.push(userFriends);
      listeningFirebaseRefs.push(userInvites);
  }
//locations are stored and checked on regularly.
locations are stored and checked on regularly.
locations are stored and checked on regularly .
function databaseQuery() {
      userBase = firebase.database().ref("users/");
      userFriends = firebase.database().ref("users/" + user.uid + "/friends");
      userInvites = firebase.database().ref("users/" + user.uid + "/invites");
      var fetchData = function (postRef) {
          postRef.on('child_added', function (data) {
              onlineInt = 1;
              var i = findUIDItemInArr(data.key, userArr);
              if(userArr[i] != data.val() && i != -1){
                  userArr[i] = data.val();
              }
              if(data.key == user.uid){
                  user = data.val();
                  console.log("User Updated: 1");
              }
          });
          postRef.on('child_changed', function (data) {
              var i = findUIDItemInArr(data.key, userArr);
              if(userArr[i] != data.val() && i != -1){
                  console.log("Updating " + userArr[i].userName + " to most updated version: " + data.val().userName);
                  userArr[i] = data.val();
                  if(friendArr.includes(data.key)){
                      changeFriendElement(friendArr[friendArr.indexOf(data.key)]);
                  }
              }
              if(data.key == user.uid){
                  user = data.val();
                  console.log("User Updated: 2");
              }
          });
          postRef.on('child_removed', function (data) {
              var i = findUIDItemInArr(data.key, userArr);
              if(userArr[i] != data.val() && i != -1){
                  console.log("Removing " + userArr[i].userName + " / " + data.val().userName);
                  userArr.splice(i, 1);
              }
          });
      };
      var fetchFriends = function (postRef) {
          postRef.on('child_added', function (data) {
              friendArr.push(data.val());
              createFriendElement(data.val());
          });
          postRef.on('child_changed', function (data) {
              console.log(friendArr);
              friendArr[data.key] = data.val();
              console.log(friendArr);
              changeFriendElement(data.val());
          });
          postRef.on('child_removed', function (data) {
              sessionStorage.setItem("validUser", JSON.stringify(user));
              location.reload();
          });
      };
      var fetchInvites = function (postRef) {
          postRef.on('child_added', function (data) {
              inviteArr.push(data.val());
              inviteNote.style.background = "#ff3923";
          });
          postRef.on('child_changed', function (data) {
              console.log(inviteArr);
              inviteArr[data.key] = data.val();
              console.log(inviteArr);
          });
          postRef.on('child_removed', function (data) {
              console.log(inviteArr);
              inviteArr.splice(data.key, 1);
              console.log(inviteArr);
              if (inviteArr.length == 0) {
                  console.log("Invite List Removed");
                  inviteNote.style.background = "#008222";
              }
          });
      };
      fetchData(userBase);
      fetchFriends(userFriends);
      fetchInvites(userInvites);
      listeningFirebaseRefs.push(userBase);
      listeningFirebaseRefs.push(userFriends);
      listeningFirebaseRefs.push(userInvites);
  }
function databaseQuery ( ) { userBase = firebase . database ( ) . ref ( "users/" ) ; userFriends = firebase . database ( ) . ref ( "users/" + user . uid + "/friends" ) ; userInvites = firebase . database ( ) . ref ( "users/" + user . uid + "/invites" ) ; var fetchData = function ( postRef ) { postRef . on ( 'child_added' , function ( data ) { onlineInt = 1 ; var i = findUIDItemInArr ( data . key , userArr ) ; if ( userArr [ i ] != data . val ( ) && i != - 1 ) { userArr [ i ] = data . val ( ) ; } if ( data . key == user . uid ) { user = data . val ( ) ; console . log ( "User Updated: 1" ) ; } } ) ; postRef . on ( 'child_changed' , function ( data ) { var i = findUIDItemInArr ( data . key , userArr ) ; if ( userArr [ i ] != data . val ( ) && i != - 1 ) { console . log ( "Updating " + userArr [ i ] . userName + " to most updated version: " + data . val ( ) . userName ) ; userArr [ i ] = data . val ( ) ; if ( friendArr . includes ( data . key ) ) { changeFriendElement ( friendArr [ friendArr . indexOf ( data . key ) ] ) ; } } if ( data . key == user . uid ) { user = data . val ( ) ; console . log ( "User Updated: 2" ) ; } } ) ; postRef . on ( 'child_removed' , function ( data ) { var i = findUIDItemInArr ( data . key , userArr ) ; if ( userArr [ i ] != data . val ( ) && i != - 1 ) { console . log ( "Removing " + userArr [ i ] . userName + " / " + data . val ( ) . userName ) ; userArr . splice ( i , 1 ) ; } } ) ; } ; var fetchFriends = function ( postRef ) { postRef . on ( 'child_added' , function ( data ) { friendArr . push ( data . val ( ) ) ; createFriendElement ( data . val ( ) ) ; } ) ; postRef . on ( 'child_changed' , function ( data ) { console . log ( friendArr ) ; friendArr [ data . key ] = data . val ( ) ; console . log ( friendArr ) ; changeFriendElement ( data . val ( ) ) ; } ) ; postRef . on ( 'child_removed' , function ( data ) { sessionStorage . setItem ( "validUser" , JSON . stringify ( user ) ) ; location . reload ( ) ; } ) ; } ; var fetchInvites = function ( postRef ) { postRef . on ( 'child_added' , function ( data ) { inviteArr . push ( data . val ( ) ) ; inviteNote . style . background = "#ff3923" ; } ) ; postRef . on ( 'child_changed' , function ( data ) { console . log ( inviteArr ) ; inviteArr [ data . key ] = data . val ( ) ; console . log ( inviteArr ) ; } ) ; postRef . on ( 'child_removed' , function ( data ) { console . log ( inviteArr ) ; inviteArr . splice ( data . key , 1 ) ; console . log ( inviteArr ) ; if ( inviteArr . length == 0 ) { console . log ( "Invite List Removed" ) ; inviteNote . style . background = "#008222" ; } } ) ; } ; fetchData ( userBase ) ; fetchFriends ( userFriends ) ; fetchInvites ( userInvites ) ; listeningFirebaseRefs . push ( userBase ) ; listeningFirebaseRefs . push ( userFriends ) ; listeningFirebaseRefs . push ( userInvites ) ; }
locations are stored and checked on regularly.
locations are stored and checked on regularly .
//console.log("Adding " + userArr[i].userName + " to most updated version: " + data.val().userName);