function databaseQuery() {

        userBase = firebase.database().ref("users/");
        userGifts = firebase.database().ref("users/" + user.uid + "/privateList/");
        userInvites = firebase.database().ref("users/" + currentUser.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 fetchGifts = function (postRef) {
            postRef.on('child_added', function (data) {
                giftArr.push(data.val());

                if(checkGiftBuyer(data.val().buyer)){
                    data.val().buyer = "";
                    updateGiftToDBBool = true;
                }

                createGiftElement(data.val().description, data.val().link, data.val().received, data.val().title,
                    data.key, data.val().where, data.val().uid, data.val().creationDate, data.val().buyer,
                    data.val().creator);
                instantiatedNodes.push(data.val());

                if(updateGiftToDBBool){
                    updateGiftError(data, data.key);
                    updateGiftToDBBool = false;
                }
            });

            postRef.on('child_changed', function(data) {
                //console.log("Changing " + data.val().uid);
                giftArr[data.key] = data.val();
                instantiatedNodes[data.key] = data.val();

                if(data.val().uid == currentModalOpen){
                    currentModalOpen = "";
                    console.log("Closed modal");
                    modal.style.display = "none";
                }

                changeGiftElement(data.val().description, data.val().link, data.val().received, data.val().title,
                    data.key, data.val().where, data.val().uid, data.val().creationDate, data.val().buyer,
                    data.val().creator);
            });

            postRef.on('child_removed', function(data) {
                sessionStorage.setItem("validGiftUser", JSON.stringify(user));
                sessionStorage.setItem("validUser", JSON.stringify(currentUser));
                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);
        fetchGifts(userGifts);
        fetchInvites(userInvites);

        listeningFirebaseRefs.push(userBase);
        listeningFirebaseRefs.push(userGifts);
        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/");
        userGifts = firebase.database().ref("users/" + user.uid + "/privateList/");
        userInvites = firebase.database().ref("users/" + currentUser.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 fetchGifts = function (postRef) {
            postRef.on('child_added', function (data) {
                giftArr.push(data.val());
                if(checkGiftBuyer(data.val().buyer)){
                    data.val().buyer = "";
                    updateGiftToDBBool = true;
                }
                createGiftElement(data.val().description, data.val().link, data.val().received, data.val().title,
                    data.key, data.val().where, data.val().uid, data.val().creationDate, data.val().buyer,
                    data.val().creator);
                instantiatedNodes.push(data.val());
                if(updateGiftToDBBool){
                    updateGiftError(data, data.key);
                    updateGiftToDBBool = false;
                }
            });
            postRef.on('child_changed', function(data) {
                giftArr[data.key] = data.val();
                instantiatedNodes[data.key] = data.val();
                if(data.val().uid == currentModalOpen){
                    currentModalOpen = "";
                    console.log("Closed modal");
                    modal.style.display = "none";
                }
                changeGiftElement(data.val().description, data.val().link, data.val().received, data.val().title,
                    data.key, data.val().where, data.val().uid, data.val().creationDate, data.val().buyer,
                    data.val().creator);
            });
            postRef.on('child_removed', function(data) {
                sessionStorage.setItem("validGiftUser", JSON.stringify(user));
                sessionStorage.setItem("validUser", JSON.stringify(currentUser));
                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);
        fetchGifts(userGifts);
        fetchInvites(userInvites);
        listeningFirebaseRefs.push(userBase);
        listeningFirebaseRefs.push(userGifts);
        listeningFirebaseRefs.push(userInvites);
    }
function databaseQuery ( ) { userBase = firebase . database ( ) . ref ( "users/" ) ; userGifts = firebase . database ( ) . ref ( "users/" + user . uid + "/privateList/" ) ; userInvites = firebase . database ( ) . ref ( "users/" + currentUser . 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 fetchGifts = function ( postRef ) { postRef . on ( 'child_added' , function ( data ) { giftArr . push ( data . val ( ) ) ; if ( checkGiftBuyer ( data . val ( ) . buyer ) ) { data . val ( ) . buyer = "" ; updateGiftToDBBool = true ; } createGiftElement ( data . val ( ) . description , data . val ( ) . link , data . val ( ) . received , data . val ( ) . title , data . key , data . val ( ) . where , data . val ( ) . uid , data . val ( ) . creationDate , data . val ( ) . buyer , data . val ( ) . creator ) ; instantiatedNodes . push ( data . val ( ) ) ; if ( updateGiftToDBBool ) { updateGiftError ( data , data . key ) ; updateGiftToDBBool = false ; } } ) ; postRef . on ( 'child_changed' , function ( data ) { giftArr [ data . key ] = data . val ( ) ; instantiatedNodes [ data . key ] = data . val ( ) ; if ( data . val ( ) . uid == currentModalOpen ) { currentModalOpen = "" ; console . log ( "Closed modal" ) ; modal . style . display = "none" ; } changeGiftElement ( data . val ( ) . description , data . val ( ) . link , data . val ( ) . received , data . val ( ) . title , data . key , data . val ( ) . where , data . val ( ) . uid , data . val ( ) . creationDate , data . val ( ) . buyer , data . val ( ) . creator ) ; } ) ; postRef . on ( 'child_removed' , function ( data ) { sessionStorage . setItem ( "validGiftUser" , JSON . stringify ( user ) ) ; sessionStorage . setItem ( "validUser" , JSON . stringify ( currentUser ) ) ; 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 ) ; fetchGifts ( userGifts ) ; fetchInvites ( userInvites ) ; listeningFirebaseRefs . push ( userBase ) ; listeningFirebaseRefs . push ( userGifts ) ; 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("Changing " + data.val().uid);