<commit_before>// client side
// chat.js
// - handle incoming chat messages
// - notify to the server the messages sent by the client
// - manage ui

const Chat = {};

Chat.makeMessageNode = function(obj) {
    var parent = document.createElement('div');
    parent.classList.add('message-wrapper');

    parent.innerHTML = `
    <div class="photo" style="background-image:url(${obj.sender.photoUrl})"></div>
    <div>
        <div class="upper-row">
            <div class="sender">${obj.sender.name}</div>
            <div class="timestamp">${new Date(obj.message.timestamp).toString()}</div>
        </div>
        <div class="message">${obj.messageBody}</div>
    </div>
    `
    return parent;
};

window.addEventListener('load', function(e) {
    var form = document.querySelector('form#fc-message-form');

    form.addEventListener('submit', function(e) {
        var messageInput = document.querySelector('#fc-m');

        var node = G.queryGroupSelected();
    	if (node == null) return toolbelt.event.stop(e);

    	var groupId = node.dataset.id;
        var senderId = document.querySelector('body').dataset['userid'];

        if (messageInput.value.trim().length === 0) {
            return toolbelt.event.stop(e);
        }

        defines.socket.emit(defines['socket-chat-message'], { 
            messageBody: messageInput.value,
            groupId: groupId,
            senderId: senderId
        });

        messageInput.value = '';
        return toolbelt.event.stop(e);
    });
});

defines.socket.on(defines['socket-chat-message'], function(obj) {
    var messages = document.querySelector('#fc-messages');
    var node = G.queryGroupSelected();
	if (node == null) return;

	if (node.dataset.id === obj.groupId) {
		messages.appendChild(Chat.makeMessageNode(obj));
	}
});

if (typeof module !== undefined && typeof module.exports != undefined) {
    module.exports = Chat;
}<commit_msg>Remove module code in chat.js<commit_after>// client side
// chat.js
// - handle incoming chat messages
// - notify to the server the messages sent by the client
// - manage ui

const Chat = {};

Chat.makeMessageNode = function(obj) {
    var parent = document.createElement('div');
    parent.classList.add('message-wrapper');

    parent.innerHTML = `
    <div class="photo" style="background-image:url(${obj.sender.photoUrl})"></div>
    <div>
        <div class="upper-row">
            <div class="sender">${obj.sender.name}</div>
            <div class="timestamp">${new Date(obj.message.timestamp).toString()}</div>
        </div>
        <div class="message">${obj.messageBody}</div>
    </div>
    `
    return parent;
};

window.addEventListener('load', function(e) {
    var form = document.querySelector('form#fc-message-form');

    form.addEventListener('submit', function(e) {
        var messageInput = document.querySelector('#fc-m');

        var node = G.queryGroupSelected();
    	if (node == null) return toolbelt.event.stop(e);

    	var groupId = node.dataset.id;
        var senderId = document.querySelector('body').dataset['userid'];

        if (messageInput.value.trim().length === 0) {
            return toolbelt.event.stop(e);
        }

        defines.socket.emit(defines['socket-chat-message'], { 
            messageBody: messageInput.value,
            groupId: groupId,
            senderId: senderId
        });

        messageInput.value = '';
        return toolbelt.event.stop(e);
    });
});

defines.socket.on(defines['socket-chat-message'], function(obj) {
    var messages = document.querySelector('#fc-messages');
    var node = G.queryGroupSelected();
	if (node == null) return;

	if (node.dataset.id === obj.groupId) {
		messages.appendChild(Chat.makeMessageNode(obj));
	}
});
{'fraction_non_alphanumeric': 0.16216216216216217, 'fraction_numerical': 0.0005351886540005352, 'mean_word_length': 2.910041841004184, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '328543', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1078, 'n_words': 215}