function databaseQuery() {

    userInitial = 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(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) {
        if (!friendArr.includes(data.val()))
          friendArr.push(data.val());
      });

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

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

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

        createInviteElement(data.val());
        inviteNote.style.background = "#ff3923";
      });

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

        changeInviteElement(data.val());
      });

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

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

    listeningFirebaseRefs.push(userInitial);
    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() {
    userInitial = 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(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) {
        if (!friendArr.includes(data.val()))
          friendArr.push(data.val());
      });
      postRef.on('child_changed', function (data) {
        console.log(friendArr);
        friendArr[data.key] = data.val();
        console.log(friendArr);
      });
      postRef.on('child_removed', function (data) {
        console.log(friendArr);
        friendArr.splice(data.key, 1);
        console.log(friendArr);
      });
    };
    var fetchInvites = function (postRef) {
      postRef.on('child_added', function (data) {
        inviteArr.push(data.val());
        createInviteElement(data.val());
        inviteNote.style.background = "#ff3923";
      });
      postRef.on('child_changed', function (data) {
        inviteArr[data.key] = data.val();
        changeInviteElement(data.val());
      });
      postRef.on('child_removed', function (data) {
        sessionStorage.setItem("validUser", JSON.stringify(user));
        location.reload();
      });
    };
    fetchData(userInitial);
    fetchFriends(userFriends);
    fetchInvites(userInvites);
    listeningFirebaseRefs.push(userInitial);
    listeningFirebaseRefs.push(userFriends);
    listeningFirebaseRefs.push(userInvites);
  }
function databaseQuery ( ) { userInitial = 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 ( 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 ) { if ( ! friendArr . includes ( data . val ( ) ) ) friendArr . push ( data . val ( ) ) ; } ) ; postRef . on ( 'child_changed' , function ( data ) { console . log ( friendArr ) ; friendArr [ data . key ] = data . val ( ) ; console . log ( friendArr ) ; } ) ; postRef . on ( 'child_removed' , function ( data ) { console . log ( friendArr ) ; friendArr . splice ( data . key , 1 ) ; console . log ( friendArr ) ; } ) ; } ; var fetchInvites = function ( postRef ) { postRef . on ( 'child_added' , function ( data ) { inviteArr . push ( data . val ( ) ) ; createInviteElement ( data . val ( ) ) ; inviteNote . style . background = "#ff3923" ; } ) ; postRef . on ( 'child_changed' , function ( data ) { inviteArr [ data . key ] = data . val ( ) ; changeInviteElement ( data . val ( ) ) ; } ) ; postRef . on ( 'child_removed' , function ( data ) { sessionStorage . setItem ( "validUser" , JSON . stringify ( user ) ) ; location . reload ( ) ; } ) ; } ; fetchData ( userInitial ) ; fetchFriends ( userFriends ) ; fetchInvites ( userInvites ) ; listeningFirebaseRefs . push ( userInitial ) ; 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);