<commit_before>﻿/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/// <reference path="../vendor/jquery.d.ts" />
/// <reference path="../vendor/jquery.cookie.d.ts" />
/// <reference path="../vendor/jquery.terminal.d.ts" />
/// <reference path="../vendor/underscore.d.ts" />
/// <reference path="../vendor/strophe.d.ts" />

module Chat {
    var minMessageBufferSize = 50;
    var messageBufferSize = minMessageBufferSize;
    var $chatInput: JQuery;
    var $chatText: JQuery;
    var hasScrolled = false;

    function AppendChat(chatBody, iconClass) {
        // This appends the chat item and escapes it
        // TODO: make a smarter process for escaping chat so we can embed some html
        var newChatItem = $('<div/>').addClass('chatItem');
        if (iconClass) newChatItem.append($('<div/>').addClass('iconClass'));
        newChatItem.append(chatBody);
        newChatItem.appendTo($chatText);
        var msgs = $('.chatItem');
        while (msgs.length > messageBufferSize) {
            msgs.first().remove();
            msgs = $('.chatItem');
        }

        if (!hasScrolled) {
            $chatText.scrollTop($chatText[0].scrollHeight);
        }
    }

    function SetTextEntryMode(mode) {
        $chatInput.attr('data-command-mode', mode.toString());
    }

    function OnChat(type, from, body, nick, iscse) {
        var msg;
        var msgClass = 'chatBody';
        messageBufferSize = Math.max(minMessageBufferSize, messageBufferSize - 1);
        var displayName;
        var jid: JID;
        switch (type) {
            case XmppMessageType.CHAT:
                jid = new JID(from);
                displayName = jid.user;
                if (nick) displayName = nick;
                msg = '[IM] [' + displayName + ']: ' + body;
                msgClass = msgClass + ' imChat';

                break;
            case XmppMessageType.GROUPCHAT:
                jid = new JID(from);
                switch (jid.user) {
                    case '_combat':
                        msg = '[combat]: ' + body;
                        msgClass = msgClass + ' combatChat';
                        break;
                    default:
                        displayName = jid.resource;
                        if (nick) displayName = nick;
                        msg = '[' + jid.user + '] [' + displayName + ']: ' + body;
                        msgClass = msgClass + ' groupChat';
                        break;
                }
                break;
            default:
                msg = 'got unknown(' + type + ') from: ' + from + ': ' + body;
        }

        var chatBody = $('<div/>').text(msg).addClass(msgClass);
        var iconClass = (iscse ? 'iscse' : null);
        AppendChat(chatBody, iconClass);
    }

    function OnSubmitChat(event) {
        // when enter key is pressed
        if (event.which == 13) {
            var body = $chatInput.val();
            var commandMode = $chatInput.attr('data-command-mode') || '0';
            if (body && body.length) {
                if (event.shiftKey || commandMode == '1') {
                    var command = $('<div/>').text(body).addClass('consoleBody command');
                    AppendChat(command, null);
                    cu.ConsoleCommand(body);
                } else {
                    ProcessCommandLine(body, event);
                }
            }
            $chatInput.val('');
            if (event.shiftKey) {
                if (commandMode == '0') {
                    SetTextEntryMode(1);
                } else {
                    SetTextEntryMode(0);
                    $chatInput.blur();
                }
            }
        }<commit_msg>fix cse icon on chat, fix input blur on chat<commit_after>﻿/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/// <reference path="../vendor/jquery.d.ts" />
/// <reference path="../vendor/jquery.cookie.d.ts" />
/// <reference path="../vendor/jquery.terminal.d.ts" />
/// <reference path="../vendor/underscore.d.ts" />
/// <reference path="../vendor/strophe.d.ts" />

module Chat {
    var minMessageBufferSize = 50;
    var messageBufferSize = minMessageBufferSize;
    var $chatInput: JQuery;
    var $chatText: JQuery;
    var hasScrolled = false;

    function AppendChat(chatBody, iconClass) {
        // This appends the chat item and escapes it
        // TODO: make a smarter process for escaping chat so we can embed some html
        var newChatItem = $('<div/>').addClass('chatItem');
        if (iconClass) newChatItem.append($('<div/>').addClass(iconClass));
        newChatItem.append(chatBody);
        newChatItem.appendTo($chatText);
        var msgs = $('.chatItem');
        while (msgs.length > messageBufferSize) {
            msgs.first().remove();
            msgs = $('.chatItem');
        }

        if (!hasScrolled) {
            $chatText.scrollTop($chatText[0].scrollHeight);
        }
    }

    function SetTextEntryMode(mode) {
        $chatInput.attr('data-command-mode', mode.toString());
    }

    function OnChat(type, from, body, nick, iscse) {
        var msg;
        var msgClass = 'chatBody';
        messageBufferSize = Math.max(minMessageBufferSize, messageBufferSize - 1);
        var displayName;
        var jid: JID;
        switch (type) {
            case XmppMessageType.CHAT:
                jid = new JID(from);
                displayName = jid.user;
                if (nick) displayName = nick;
                msg = '[IM] [' + displayName + ']: ' + body;
                msgClass = msgClass + ' imChat';

                break;
            case XmppMessageType.GROUPCHAT:
                jid = new JID(from);
                switch (jid.user) {
                    case '_combat':
                        msg = '[combat]: ' + body;
                        msgClass = msgClass + ' combatChat';
                        break;
                    default:
                        displayName = jid.resource;
                        if (nick) displayName = nick;
                        msg = '[' + jid.user + '] [' + displayName + ']: ' + body;
                        msgClass = msgClass + ' groupChat';
                        break;
                }
                break;
            default:
                msg = 'got unknown(' + type + ') from: ' + from + ': ' + body;
        }

        var chatBody = $('<div/>').text(msg).addClass(msgClass);
        var iconClass = (iscse ? 'iscse' : null);
        AppendChat(chatBody, iconClass);
    }

    function OnSubmitChat(event) {
        // when enter key is pressed
        if (event.which == 13) {
            var body = $chatInput.val();
            var commandMode = $chatInput.attr('data-command-mode') || '0';
            if (body && body.length) {
                if (event.shiftKey || commandMode == '1') {
                    var command = $('<div/>').text(body).addClass('consoleBody command');
                    AppendChat(command, null);
                    cu.ConsoleCommand(body);
                } else {
                    ProcessCommandLine(body, event);
                }
            }
            $chatInput.val('');
            if (event.shiftKey) {
                if (commandMode == '0') {
                    SetTextEntryMode(1);
                } else {
                    SetTextEntryMode(0);
                    $chatInput.blur();
                }
            } else {
                $chatInput.blur();
            }
        }
{'fraction_non_alphanumeric': 0.1322335352493878, 'fraction_numerical': 0.0038664776388709883, 'mean_word_length': 1.495979414602766, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, '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': '1008251', 'n_tokens_mistral': 2177, 'n_tokens_neox': 2055, 'n_words': 503}