function databaseQuery() {

        userReadNotifications = firebase.database().ref("users/" + user.uid + "/readNotifications");
        userNotifications = firebase.database().ref("users/" + user.uid + "/notifications");
        userInvites = firebase.database().ref("users/" + user.uid + "/invites");

        var fetchReadNotifications = function (postRef){
            postRef.on('child_added', function (data) {
                if(!readNotificationArr.includes(data.val())) {
                    readNotificationArr.push(data.val());
                }
                if (notificationArr.includes(data.val())){
                    var liItemUpdate = document.getElementById("notification" + notificationArr.indexOf(data.val()));
                    liItemUpdate.className += " checked";
                }
            });

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

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

        var fetchNotifications = function (postRef) {
            postRef.on('child_added', function (data) {
                notificationArr.push(data.val());
                createNotificationElement(data.val(), data.key);
            });

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

            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) {
                inviteArr[data.key] = data.val();
            });

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

        fetchReadNotifications(userReadNotifications);
        fetchNotifications(userNotifications);
        fetchInvites(userInvites);

        listeningFirebaseRefs.push(userReadNotifications);
        listeningFirebaseRefs.push(userNotifications);
        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() {
        userReadNotifications = firebase.database().ref("users/" + user.uid + "/readNotifications");
        userNotifications = firebase.database().ref("users/" + user.uid + "/notifications");
        userInvites = firebase.database().ref("users/" + user.uid + "/invites");
        var fetchReadNotifications = function (postRef){
            postRef.on('child_added', function (data) {
                if(!readNotificationArr.includes(data.val())) {
                    readNotificationArr.push(data.val());
                }
                if (notificationArr.includes(data.val())){
                    var liItemUpdate = document.getElementById("notification" + notificationArr.indexOf(data.val()));
                    liItemUpdate.className += " checked";
                }
            });
            postRef.on('child_changed', function (data) {
                readNotificationArr[data.key] = data.val();
            });
            postRef.on('child_removed', function (data) {
                sessionStorage.setItem("validUser", JSON.stringify(user));
                location.reload();
            });
        };
        var fetchNotifications = function (postRef) {
            postRef.on('child_added', function (data) {
                notificationArr.push(data.val());
                createNotificationElement(data.val(), data.key);
            });
            postRef.on('child_changed', function (data) {
                notificationArr[data.key] = data.val();
                changeNotificationElement(data.val(), data.key);
            });
            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) {
                inviteArr[data.key] = data.val();
            });
            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";
                }
            });
        };
        fetchReadNotifications(userReadNotifications);
        fetchNotifications(userNotifications);
        fetchInvites(userInvites);
        listeningFirebaseRefs.push(userReadNotifications);
        listeningFirebaseRefs.push(userNotifications);
        listeningFirebaseRefs.push(userInvites);
    }
function databaseQuery ( ) { userReadNotifications = firebase . database ( ) . ref ( "users/" + user . uid + "/readNotifications" ) ; userNotifications = firebase . database ( ) . ref ( "users/" + user . uid + "/notifications" ) ; userInvites = firebase . database ( ) . ref ( "users/" + user . uid + "/invites" ) ; var fetchReadNotifications = function ( postRef ) { postRef . on ( 'child_added' , function ( data ) { if ( ! readNotificationArr . includes ( data . val ( ) ) ) { readNotificationArr . push ( data . val ( ) ) ; } if ( notificationArr . includes ( data . val ( ) ) ) { var liItemUpdate = document . getElementById ( "notification" + notificationArr . indexOf ( data . val ( ) ) ) ; liItemUpdate . className += " checked" ; } } ) ; postRef . on ( 'child_changed' , function ( data ) { readNotificationArr [ data . key ] = data . val ( ) ; } ) ; postRef . on ( 'child_removed' , function ( data ) { sessionStorage . setItem ( "validUser" , JSON . stringify ( user ) ) ; location . reload ( ) ; } ) ; } ; var fetchNotifications = function ( postRef ) { postRef . on ( 'child_added' , function ( data ) { notificationArr . push ( data . val ( ) ) ; createNotificationElement ( data . val ( ) , data . key ) ; } ) ; postRef . on ( 'child_changed' , function ( data ) { notificationArr [ data . key ] = data . val ( ) ; changeNotificationElement ( data . val ( ) , data . key ) ; } ) ; 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 ) { inviteArr [ data . key ] = data . val ( ) ; } ) ; 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" ; } } ) ; } ; fetchReadNotifications ( userReadNotifications ) ; fetchNotifications ( userNotifications ) ; fetchInvites ( userInvites ) ; listeningFirebaseRefs . push ( userReadNotifications ) ; listeningFirebaseRefs . push ( userNotifications ) ; listeningFirebaseRefs . push ( userInvites ) ; }
locations are stored and checked on regularly.
locations are stored and checked on regularly .