function databaseQuery() {

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

        var fetchData = function (postRef) {
            postRef.on('child_added', function (data) {
                createUserElement(data.val());

                if(onlineInt == 0) {
                    onlineInt = 1;
                    initializeGlobalNotification();
                }

                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) {
                changeUserElement(data.val());

                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");
                }

                if(currentModalOpen == data.key) {
                    modal.style.display = "none";
                    currentModalOpen = "";
                }
            });

            postRef.on('child_removed', function (data) {
                removeUserElement(data.val().uid);

                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);
                }

                if(currentModalOpen == data.key) {
                    modal.style.display = "none";
                    currentModalOpen = "";
                }
            });
        };

        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(userInitial);
        fetchInvites(userInvites);

        listeningFirebaseRefs.push(userInitial);
        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/");
        userInvites = firebase.database().ref("users/" + user.uid + "/invites");
        var fetchData = function (postRef) {
            postRef.on('child_added', function (data) {
                createUserElement(data.val());
                if(onlineInt == 0) {
                    onlineInt = 1;
                    initializeGlobalNotification();
                }
                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();
                }
            });
            postRef.on('child_changed', function (data) {
                changeUserElement(data.val());
                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();
                }
                if(currentModalOpen == data.key) {
                    modal.style.display = "none";
                    currentModalOpen = "";
                }
            });
            postRef.on('child_removed', function (data) {
                removeUserElement(data.val().uid);
                var i = findUIDItemInArr(data.key, userArr);
                if(userArr[i] != data.val() && i != -1){
                    userArr.splice(i, 1);
                }
                if(currentModalOpen == data.key) {
                    modal.style.display = "none";
                    currentModalOpen = "";
                }
            });
        };
        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(userInitial);
        fetchInvites(userInvites);
        listeningFirebaseRefs.push(userInitial);
        listeningFirebaseRefs.push(userInvites);
    }
function databaseQuery ( ) { userInitial = firebase . database ( ) . ref ( "users/" ) ; userInvites = firebase . database ( ) . ref ( "users/" + user . uid + "/invites" ) ; var fetchData = function ( postRef ) { postRef . on ( 'child_added' , function ( data ) { createUserElement ( data . val ( ) ) ; if ( onlineInt == 0 ) { onlineInt = 1 ; initializeGlobalNotification ( ) ; } 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 ( ) ; } } ) ; postRef . on ( 'child_changed' , function ( data ) { changeUserElement ( data . val ( ) ) ; 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 ( ) ; } if ( currentModalOpen == data . key ) { modal . style . display = "none" ; currentModalOpen = "" ; } } ) ; postRef . on ( 'child_removed' , function ( data ) { removeUserElement ( data . val ( ) . uid ) ; var i = findUIDItemInArr ( data . key , userArr ) ; if ( userArr [ i ] != data . val ( ) && i != - 1 ) { userArr . splice ( i , 1 ) ; } if ( currentModalOpen == data . key ) { modal . style . display = "none" ; currentModalOpen = "" ; } } ) ; } ; 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 ( userInitial ) ; fetchInvites ( userInvites ) ; listeningFirebaseRefs . push ( userInitial ) ; 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); //console.log("User Updated: 1"); //console.log("Updating " + userArr[i].userName + " to most updated version: " + data.val().userName); //console.log("User Updated: 2"); //console.log("Removing " + userArr[i].userName + " / " + data.val().userName);