<commit_before>/* handles the communication between client-server-client and clientA-clientA */
$(document).ready(function(){

    function autoScroll(){ //scrolls to the most recent message
        var scrollSize = $('#messageboard')[0].scrollHeight;
        $('#messageboard').animate({ scrollTop: scrollSize}, 0);
    }
    //handles communication between client&user
    var clientObj = {
        userSettings: {
            autoScroll: '',
            toFix: ''
        },
        fromUser: function(msg){
            var msgObj = {
                message: msg
            };
            socket.emit('message', msgObj); //send to server
        },
        toUser: function(msg){
            $('#result').append('<li>' + msg + '</li>');
            //check if autoscrolling is enabled
            if(clientObj.userSettings.autoScroll === 'enabled'){
                autoScroll();
            }
        },
        appendEnabledOptions: function(functionObj){
            //appends a label with the enabled functions
            $('#enabled-options').append('<label class="' + 
                                         functionObj.functionType + '">' + 
                                         functionObj.functionType + ': ' + 
                                         functionObj.user + '</label>'
                                        );
        },
        messageHandler: function(msg){
            if(msg.slice(0,1) === '\\'){
                var commandArray = msg.split(' ');// example: _
                // \to user msg > [\to,user,msg] > [1] = user
                clientObj.commandList(commandArray, msg);
            } else {
                if(clientObj.userSettings.toFix.length > 0){
                    var msgObj = {
                        message: msg,
                        sendTo: clientObj.userSettings.toFix
                    };
                    clientObj.toUser('<label class="pm-send" name="' + socket.id + '">You:</label> ' + msgObj.message);
                    socket.emit('privateMessage', msgObj);
                } else {
                    clientObj.toUser('<label class="normal-msg-sent" name="' + socket.id + '">You:</label> ' + msg);
                    clientObj.fromUser(msg);   
                }
            }
        },
        commandList: function(commandArray, msg){
            switch(commandArray[0]){
                case '\\to':
                    //takes the total length of command+code
                    if(commandArray[1] && commandArray[2]){
                    //if there's a user and a message (not null)
                        var commandLength = commandArray[0].length + commandArray[1].length;
                        var msgObj = {
                            message: msg.slice(commandLength+2), // +two spaces _
                            //_ between [0]&[1] and [1]&[2]
                            sendTo: commandArray[1] //[1] = user
                        };
                        //***IMPORTANT
                        //in the future, separate this nex code. [see messagehandler:tofix ]
                        clientObj.toUser('<label class="pm-send" name="' + socket.id + '">You:</label> ' + msgObj.message);<commit_msg>just a note added<commit_after>/* handles the communication between client-server-client and clientA-clientA */
$(document).ready(function(){

    function autoScroll(){ //scrolls to the most recent message
        var scrollSize = $('#messageboard')[0].scrollHeight;
        $('#messageboard').animate({ scrollTop: scrollSize}, 0);
    }
    //handles communication between client&user
    var clientObj = {
        userSettings: {
            autoScroll: '',
            toFix: ''
        },
        fromUser: function(msg){
            var msgObj = {
                message: msg
            };
            socket.emit('message', msgObj); //send to server
        },
        toUser: function(msg){
            $('#result').append('<li>' + msg + '</li>');
            //check if autoscrolling is enabled
            if(clientObj.userSettings.autoScroll === 'enabled'){
                autoScroll();
            }
        },
        appendEnabledOptions: function(functionObj){
            //appends a label with the enabled functions
            $('#enabled-options').append('<label class="' + 
                                         functionObj.functionType + '">' + 
                                         functionObj.functionType + ': ' + 
                                         functionObj.user + '</label>'
                                        );
        },
        messageHandler: function(msg){
            if(msg.slice(0,1) === '\\'){
                var commandArray = msg.split(' ');// example: _
                // \to user msg > [\to,user,msg] > [1] = user
                clientObj.commandList(commandArray, msg);
            } else {
                if(clientObj.userSettings.toFix.length > 0){
                    //if there's a to-fix user defined
                    var msgObj = {
                        message: msg,
                        sendTo: clientObj.userSettings.toFix
                    };
                    clientObj.toUser('<label class="pm-send" name="' + socket.id + '">You:</label> ' + msgObj.message);
                    socket.emit('privateMessage', msgObj);
                } else {
                    //if it's a normal message
                    clientObj.toUser('<label class="normal-msg-sent" name="' + socket.id + '">You:</label> ' + msg);
                    clientObj.fromUser(msg);   
                }
            }
        },
        commandList: function(commandArray, msg){
            switch(commandArray[0]){
                case '\\to':
                    //takes the total length of command+code
                    if(commandArray[1] && commandArray[2]){
                    //if there's a user and a message (not null)
                        var commandLength = commandArray[0].length + commandArray[1].length;
                        var msgObj = {
                            message: msg.slice(commandLength+2), // +two spaces _
                            //_ between [0]&[1] and [1]&[2]
                            sendTo: commandArray[1] //[1] = user
                        };
                        //***IMPORTANT
                        //in the future, separate this nex code. [see messagehandler:tofix ]
                        clientObj.toUser('<label class="pm-send" name="' + socket.id + '">You:</label> ' + msgObj.message);
{'fraction_non_alphanumeric': 0.12925482980680772, 'fraction_numerical': 0.005519779208831647, 'mean_word_length': 1.2936005625879043, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3074861', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1528, 'n_words': 351}