function main() {
            populateMessagesOnPageLoad()
            populateUsersOnPageLoad()

            messagesService.on("removed", (message) => {
                var msgId = message._id
                $(`.media[data-id="${msgId}"]`).remove()
            })

            $("#chat-area").on("click", ".delete-comment", function () {
                var msgId = $(this).closest(".media").attr("data-id")
                messagesService.remove(msgId)
            })

            $("#logout-icon").on("click", function () {
                client.logout()
                window.location.href = `${serverurl}/login.html`
            })

            /*
            create new message code
            */
            $("#submit-message-form").submit(function (e) {
                e.preventDefault();
                var $msgText = $("#msg-text");
                var msgText = $msgText.val();
                $msgText.val("");

                if (msgText.trim().length) {
                    messagesService.create({
                        text: msgText
                    }).catch((err) => {
                        alert('There was an error!')
                    })
                }
            })


            messagesService.on('created', (message) => {
                var newMessage = new Message(message)

                $("#chat-area").append(newMessage.getMessageHtmlString());
                $('html,body').animate({ scrollTop: $(document).height() }, "slow")

            })
            usersService.on('patch', user => {
                const userId = user._id
                const userName = user.userName
                if (user.isOnline === false) {
                    if (userIsDom(userId)) {
                        removeUserFromDom(userId)
                    }
                }
                if (user.isOnline === true) {
                    if (!userIsDom(userId)) {
                        addUserDom(user)
                    }
                }
            })


        }
/**
 * Function runs all page load scripts after authentication is completed.
 */
Function runs all page load scripts after authentication is completed.
Function runs all page load scripts after authentication is completed .
function main() {
            populateMessagesOnPageLoad()
            populateUsersOnPageLoad()
            messagesService.on("removed", (message) => {
                var msgId = message._id
                $(`.media[data-id="${msgId}"]`).remove()
            })
            $("#chat-area").on("click", ".delete-comment", function () {
                var msgId = $(this).closest(".media").attr("data-id")
                messagesService.remove(msgId)
            })
            $("#logout-icon").on("click", function () {
                client.logout()
                window.location.href = `${serverurl}/login.html`
            })
            $("#submit-message-form").submit(function (e) {
                e.preventDefault();
                var $msgText = $("#msg-text");
                var msgText = $msgText.val();
                $msgText.val("");
                if (msgText.trim().length) {
                    messagesService.create({
                        text: msgText
                    }).catch((err) => {
                        alert('There was an error!')
                    })
                }
            })
            messagesService.on('created', (message) => {
                var newMessage = new Message(message)
                $("#chat-area").append(newMessage.getMessageHtmlString());
                $('html,body').animate({ scrollTop: $(document).height() }, "slow")
            })
            usersService.on('patch', user => {
                const userId = user._id
                const userName = user.userName
                if (user.isOnline === false) {
                    if (userIsDom(userId)) {
                        removeUserFromDom(userId)
                    }
                }
                if (user.isOnline === true) {
                    if (!userIsDom(userId)) {
                        addUserDom(user)
                    }
                }
            })
        }
function main ( ) { populateMessagesOnPageLoad ( ) populateUsersOnPageLoad ( ) messagesService . on ( "removed" , ( message ) => { var msgId = message . _id $ ( ` ${ msgId } ` ) . remove ( ) } ) $ ( "#chat-area" ) . on ( "click" , ".delete-comment" , function ( ) { var msgId = $ ( this ) . closest ( ".media" ) . attr ( "data-id" ) messagesService . remove ( msgId ) } ) $ ( "#logout-icon" ) . on ( "click" , function ( ) { client . logout ( ) window . location . href = ` ${ serverurl } ` } ) $ ( "#submit-message-form" ) . submit ( function ( e ) { e . preventDefault ( ) ; var $msgText = $ ( "#msg-text" ) ; var msgText = $msgText . val ( ) ; $msgText . val ( "" ) ; if ( msgText . trim ( ) . length ) { messagesService . create ( { text : msgText } ) . catch ( ( err ) => { alert ( 'There was an error!' ) } ) } } ) messagesService . on ( 'created' , ( message ) => { var newMessage = new Message ( message ) $ ( "#chat-area" ) . append ( newMessage . getMessageHtmlString ( ) ) ; $ ( 'html,body' ) . animate ( { scrollTop : $ ( document ) . height ( ) } , "slow" ) } ) usersService . on ( 'patch' , user => { const userId = user . _id const userName = user . userName if ( user . isOnline === false ) { if ( userIsDom ( userId ) ) { removeUserFromDom ( userId ) } } if ( user . isOnline === true ) { if ( ! userIsDom ( userId ) ) { addUserDom ( user ) } } } ) }
Function runs all page load scripts after authentication is completed.
Function runs all page load scripts after authentication is completed .
/*
            create new message code
            */