<commit_before>/**
 * Chat system
 *
 * @param {SocketClient} client
 */
function Chat(client)
{
    BaseChat.call(this);

    this.client  = client;
    this.message = new Message(null, this.client);
    this.room    = null;
    this.$scope  = null;
    this.feed    = null;

    this.talk       = this.talk.bind(this);
    this.onTalk     = this.onTalk.bind(this);
    this.scrollDown = this.scrollDown.bind(this);

    this.attachEvents();
}

Chat.prototype = Object.create(BaseChat.prototype);
Chat.prototype.constructor = Chat;

/**
 * Curvybot profile
 *
 * @type {Object}
 */
Chat.prototype.curvybot = {
    name: 'Curvybot',
    color: '#ff8069',
    icon: 'icon-megaphone'
};

/**
 * Attach events
 */
Chat.prototype.attachEvents = function()
{
    this.client.on('room:talk', this.onTalk);
};

/**
 * Detach events
 */
Chat.prototype.detachEvents = function()
{
    this.client.off('room:talk', this.onTalk);
};

/**
 * Set player
 *
 * @param {Player} player
 */
Chat.prototype.setPlayer = function(player)
{
    if (this.room) {
        this.message.player = player;
    }
};

/**
 * Set room
 *
 * @param {Room} room
 */
Chat.prototype.setRoom = function(room)
{
    if (!this.room || !this.room.equal(room)) {
        this.room = room;
        this.clearMessages();
    }
};

/**
 * Set scope
 */
Chat.prototype.setScope = function($scope)
{
    this.$scope = $scope;
    this.feed   = document.getElementById('feed');

    this.$scope.messages         = this.messages;
    this.$scope.submitTalk       = this.talk;
    this.$scope.currentMessage   = this.message;
    this.$scope.messageMaxLength = Message.prototype.maxLength;

    setTimeout(this.scrollDown, 0);
};

/**
 * Refresh
 */
Chat.prototype.refresh = function()
{
    try {
        this.$scope.$apply();
    } catch (e) {

    }

    this.scrollDown();
};

/**
 * Scroll down
 */
Chat.prototype.scrollDown = function()
{
    if (this.feed) {
        this.feed.scrollTop = this.feed.scrollHeight;
    }
};

/**
 * Talk
 */
Chat.prototype.talk = function()
{
    var chat = this;

    if (this.message.content.length) {
        this.client.addEvent(
            'room:talk',
            this.message.serialize(),
            function (result) {
                if (result.success) {
                    chat.message.clear();
                    chat.refresh();
                } else {
                    console.error('Could not send %s', chat.message);
                }
            }
        );
    }
};

/**
 * On talk
 */
Chat.prototype.onTalk = function(e)
{
    var data = e.detail,
        player = this.room.getPlayerByClient(data.client),
        message = new Message(data.content, data.client, player ? player : {name: data.name, color: data.color}, data.creation);

    this.addMessage(message);
    this.refresh();
};

/**
 * Clear
 */
Chat.prototype.clear = function()
{
    this.clearMessages();
    this.message = new Message(null, this.client);
    this.room    = null;
    this.$scope  = null;<commit_msg>Fixed alignment<commit_after>/**
 * Chat system
 *
 * @param {SocketClient} client
 */
function Chat(client)
{
    BaseChat.call(this);

    this.client  = client;
    this.message = new Message(null, this.client);
    this.room    = null;
    this.$scope  = null;
    this.feed    = null;

    this.talk       = this.talk.bind(this);
    this.onTalk     = this.onTalk.bind(this);
    this.scrollDown = this.scrollDown.bind(this);

    this.attachEvents();
}

Chat.prototype = Object.create(BaseChat.prototype);
Chat.prototype.constructor = Chat;

/**
 * Curvybot profile
 *
 * @type {Object}
 */
Chat.prototype.curvybot = {
    name: 'Curvybot',
    color: '#ff8069',
    icon: 'icon-megaphone'
};

/**
 * Attach events
 */
Chat.prototype.attachEvents = function()
{
    this.client.on('room:talk', this.onTalk);
};

/**
 * Detach events
 */
Chat.prototype.detachEvents = function()
{
    this.client.off('room:talk', this.onTalk);
};

/**
 * Set player
 *
 * @param {Player} player
 */
Chat.prototype.setPlayer = function(player)
{
    if (this.room) {
        this.message.player = player;
    }
};

/**
 * Set room
 *
 * @param {Room} room
 */
Chat.prototype.setRoom = function(room)
{
    if (!this.room || !this.room.equal(room)) {
        this.room = room;
        this.clearMessages();
    }
};

/**
 * Set scope
 */
Chat.prototype.setScope = function($scope)
{
    this.$scope = $scope;
    this.feed   = document.getElementById('feed');

    this.$scope.messages         = this.messages;
    this.$scope.submitTalk       = this.talk;
    this.$scope.currentMessage   = this.message;
    this.$scope.messageMaxLength = Message.prototype.maxLength;

    setTimeout(this.scrollDown, 0);
};

/**
 * Refresh
 */
Chat.prototype.refresh = function()
{
    try {
        this.$scope.$apply();
    } catch (e) {

    }

    this.scrollDown();
};

/**
 * Scroll down
 */
Chat.prototype.scrollDown = function()
{
    if (this.feed) {
        this.feed.scrollTop = this.feed.scrollHeight;
    }
};

/**
 * Talk
 */
Chat.prototype.talk = function()
{
    var chat = this;

    if (this.message.content.length) {
        this.client.addEvent(
            'room:talk',
            this.message.serialize(),
            function (result) {
                if (result.success) {
                    chat.message.clear();
                    chat.refresh();
                } else {
                    console.error('Could not send %s', chat.message);
                }
            }
        );
    }
};

/**
 * On talk
 */
Chat.prototype.onTalk = function(e)
{
    var data    = e.detail,
        player  = this.room.getPlayerByClient(data.client),
        message = new Message(data.content, data.client, player ? player : {name: data.name, color: data.color}, data.creation);

    this.addMessage(message);
    this.refresh();
};

/**
 * Clear
 */
Chat.prototype.clear = function()
{
    this.clearMessages();
    this.message = new Message(null, this.client);
    this.room    = null;
    this.$scope  = null;
{'fraction_non_alphanumeric': 0.16117216117216118, 'fraction_numerical': 0.001665001665001665, 'mean_word_length': 2.254062838569881, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4481917', 'n_tokens_mistral': 1968, 'n_tokens_neox': 1914, 'n_words': 340}