client/src/views/channel.js
function(msg) {
        var nick_hex, time_difference,
            message_words,
            sb = this.model.get('scrollback'),
            network = this.model.get('network'),
            nick,
            regexpStr,
            prev_msg = sb[sb.length-2],
            hour, pm, am_pm_locale_key;

        // Clone the msg object so we dont modify the original
        msg = _.clone(msg);

        // Defaults
        msg.css_classes = '';
        msg.nick_style = '';
        msg.is_highlight = false;
        msg.time_string = '';

        // Nick + custom highlight detecting
        nick = network ? network.get('nick') : '';
        if (nick && msg.nick.localeCompare(nick) !== 0) {
            // Build a list of all highlights and escape them for regex
            regexpStr = _.chain((_kiwi.global.settings.get('custom_highlights') || '').split(/[\s,]+/))
                .compact()
                .concat(nick)
                .map(_.escapeRegExp)
                .join('|')
                .value();

            if (msg.msg.search(new RegExp('(\\b|\\W|^)(' + regexpStr + ')(\\b|\\W|$)', 'i')) > -1) {
                msg.is_highlight = true;
                msg.css_classes += ' highlight';
            }
        }

        message_words = msg.msg.split(' ');
        message_words = _.map(message_words, function(word) {
            var parsed_word;

            parsed_word = this.parseMessageUrls(word);
            if (typeof parsed_word === 'string') return parsed_word;

            parsed_word = this.parseMessageChannels(word);
            if (typeof parsed_word === 'string') return parsed_word;

            parsed_word = this.parseMessageNicks(word, (msg.type === 'privmsg'));
            if (typeof parsed_word === 'string') return parsed_word;

            parsed_word = _.escape(word);

            // Replace text emoticons with images
            if (_kiwi.global.settings.get('show_emoticons')) {
                parsed_word = emoticonFromText(parsed_word);
            }

            return parsed_word;
        }, this);

        msg.unparsed_msg = msg.msg;
        msg.msg = message_words.join(' ');

        // Convert IRC formatting into HTML formatting
        msg.msg = formatIRCMsg(msg.msg);

        // Add some style to the nick
        msg.nick_style = this.getNickStyles(msg.nick).asCssString();

        // Generate a hex string from the nick to be used as a CSS class name
        nick_hex = '';
        if (msg.nick) {
            _.map(msg.nick.split(''), function (char) {
                nick_hex += char.charCodeAt(0).toString(16);
            });
            msg.css_classes += ' nick_' + nick_hex;
        }

        if (prev_msg) {
            // Time difference between this message and the last (in minutes)
            time_difference = (msg.time.getTime() - prev_msg.time.getTime())/1000/60;
            if (prev_msg.nick === msg.nick && time_difference < 1) {
                msg.css_classes += ' repeated_nick';
            }
        }

        // Build up and add the line
        if (_kiwi.global.settings.get('use_24_hour_timestamps')) {
            msg.time_string = msg.time.getHours().toString().lpad(2, "0") + ":" + msg.time.getMinutes().toString().lpad(2, "0") + ":" + msg.time.getSeconds().toString().lpad(2, "0");
        } else {
            hour = msg.time.getHours();
            pm = hour > 11;

            hour = hour % 12;
            if (hour === 0)
                hour = 12;

            am_pm_locale_key = pm ?
                'client_views_panel_timestamp_pm' :
                'client_views_panel_timestamp_am';

            msg.time_string = translateText(am_pm_locale_key, hour + ":" + msg.time.getMinutes().toString().lpad(2, "0") + ":" + msg.time.getSeconds().toString().lpad(2, "0"));
        }

        return msg;
    }
function(msg) {
        var nick_hex, time_difference,
            message_words,
            sb = this.model.get('scrollback'),
            network = this.model.get('network'),
            nick,
            regexpStr,
            prev_msg = sb[sb.length-2],
            hour, pm, am_pm_locale_key;

        // Clone the msg object so we dont modify the original
        msg = _.clone(msg);

        // Defaults
        msg.css_classes = '';
        msg.nick_style = '';
        msg.is_highlight = false;
        msg.time_string = '';

        // Nick + custom highlight detecting
        nick = network ? network.get('nick') : '';
        if (nick && msg.nick.localeCompare(nick) !== 0) {
            // Build a list of all highlights and escape them for regex
            regexpStr = _.chain((_kiwi.global.settings.get('custom_highlights') || '').split(/[\s,]+/))
                .compact()
                .concat(nick)
                .map(_.escapeRegExp)
                .join('|')
                .value();

            if (msg.msg.search(new RegExp('(\\b|\\W|^)(' + regexpStr + ')(\\b|\\W|$)', 'i')) > -1) {
                msg.is_highlight = true;
                msg.css_classes += ' highlight';
            }
        }

        message_words = msg.msg.split(' ');
        message_words = _.map(message_words, function(word) {
            var parsed_word;

            parsed_word = this.parseMessageUrls(word);
            if (typeof parsed_word === 'string') return parsed_word;

            parsed_word = this.parseMessageChannels(word);
            if (typeof parsed_word === 'string') return parsed_word;

            parsed_word = this.parseMessageNicks(word, (msg.type === 'privmsg'));
            if (typeof parsed_word === 'string') return parsed_word;

            parsed_word = _.escape(word);

            // Replace text emoticons with images
            if (_kiwi.global.settings.get('show_emoticons')) {
                parsed_word = emoticonFromText(parsed_word);
            }

            return parsed_word;
        }, this);

        msg.unparsed_msg = msg.msg;
        msg.msg = message_words.join(' ');

        // Convert IRC formatting into HTML formatting
        msg.msg = formatIRCMsg(msg.msg);

        // Add some style to the nick
        msg.nick_style = this.getNickStyles(msg.nick).asCssString();

        // Generate a hex string from the nick to be used as a CSS class name
        nick_hex = '';
        if (msg.nick) {
            _.map(msg.nick.split(''), function (char) {
                nick_hex += char.charCodeAt(0).toString(16);
            });
            msg.css_classes += ' nick_' + nick_hex;
        }

        if (prev_msg) {
            // Time difference between this message and the last (in minutes)
            time_difference = (msg.time.getTime() - prev_msg.time.getTime())/1000/60;
            if (prev_msg.nick === msg.nick && time_difference < 1) {
                msg.css_classes += ' repeated_nick';
            }
        }

        // Build up and add the line
        if (_kiwi.global.settings.get('use_24_hour_timestamps')) {
            msg.time_string = msg.time.getHours().toString().lpad(2, "0") + ":" + msg.time.getMinutes().toString().lpad(2, "0") + ":" + msg.time.getSeconds().toString().lpad(2, "0");
        } else {
            hour = msg.time.getHours();
            pm = hour > 11;

            hour = hour % 12;
            if (hour === 0)
                hour = 12;

            am_pm_locale_key = pm ?
                'client_views_panel_timestamp_pm' :
                'client_views_panel_timestamp_am';

            msg.time_string = translateText(am_pm_locale_key, hour + ":" + msg.time.getMinutes().toString().lpad(2, "0") + ":" + msg.time.getSeconds().toString().lpad(2, "0"));
        }

        return msg;
    }
function ( msg ) { var nick_hex , time_difference , message_words , sb = this . model . get ( 'scrollback' ) , network = this . model . get ( 'network' ) , nick , regexpStr , prev_msg = sb [ sb . length - 2 ] , hour , pm , am_pm_locale_key ; // Clone the msg object so we dont modify the original msg = _ . clone ( msg ) ; // Defaults msg . css_classes = '' ; msg . nick_style = '' ; msg . is_highlight = false ; msg . time_string = '' ; // Nick + custom highlight detecting nick = network ? network . get ( 'nick' ) : '' ; if ( nick && msg . nick . localeCompare ( nick ) !== 0 ) { // Build a list of all highlights and escape them for regex regexpStr = _ . chain ( ( _kiwi . global . settings . get ( 'custom_highlights' ) || '' ) . split ( / [\s,]+ / ) ) . compact ( ) . concat ( nick ) . map ( _ . escapeRegExp ) . join ( '|' ) . value ( ) ; if ( msg . msg . search ( new RegExp ( '(\\b|\\W|^)(' + regexpStr + ')(\\b|\\W|$)' , 'i' ) ) > - 1 ) { msg . is_highlight = true ; msg . css_classes += ' highlight' ; } } message_words = msg . msg . split ( ' ' ) ; message_words = _ . map ( message_words , function ( word ) { var parsed_word ; parsed_word = this . parseMessageUrls ( word ) ; if ( typeof parsed_word === 'string' ) return parsed_word ; parsed_word = this . parseMessageChannels ( word ) ; if ( typeof parsed_word === 'string' ) return parsed_word ; parsed_word = this . parseMessageNicks ( word , ( msg . type === 'privmsg' ) ) ; if ( typeof parsed_word === 'string' ) return parsed_word ; parsed_word = _ . escape ( word ) ; // Replace text emoticons with images if ( _kiwi . global . settings . get ( 'show_emoticons' ) ) { parsed_word = emoticonFromText ( parsed_word ) ; } return parsed_word ; } , this ) ; msg . unparsed_msg = msg . msg ; msg . msg = message_words . join ( ' ' ) ; // Convert IRC formatting into HTML formatting msg . msg = formatIRCMsg ( msg . msg ) ; // Add some style to the nick msg . nick_style = this . getNickStyles ( msg . nick ) . asCssString ( ) ; // Generate a hex string from the nick to be used as a CSS class name nick_hex = '' ; if ( msg . nick ) { _ . map ( msg . nick . split ( '' ) , function ( char ) { nick_hex += char . charCodeAt ( 0 ) . toString ( 16 ) ; } ) ; msg . css_classes += ' nick_' + nick_hex ; } if ( prev_msg ) { // Time difference between this message and the last (in minutes) time_difference = ( msg . time . getTime ( ) - prev_msg . time . getTime ( ) ) / 1000 / 60 ; if ( prev_msg . nick === msg . nick && time_difference < 1 ) { msg . css_classes += ' repeated_nick' ; } } // Build up and add the line if ( _kiwi . global . settings . get ( 'use_24_hour_timestamps' ) ) { msg . time_string = msg . time . getHours ( ) . toString ( ) . lpad ( 2 , "0" ) + ":" + msg . time . getMinutes ( ) . toString ( ) . lpad ( 2 , "0" ) + ":" + msg . time . getSeconds ( ) . toString ( ) . lpad ( 2 , "0" ) ; } else { hour = msg . time . getHours ( ) ; pm = hour > 11 ; hour = hour % 12 ; if ( hour === 0 ) hour = 12 ; am_pm_locale_key = pm ? 'client_views_panel_timestamp_pm' : 'client_views_panel_timestamp_am' ; msg . time_string = translateText ( am_pm_locale_key , hour + ":" + msg . time . getMinutes ( ) . toString ( ) . lpad ( 2 , "0" ) + ":" + msg . time . getSeconds ( ) . toString ( ) . lpad ( 2 , "0" ) ) ; } return msg ; }
Takes an IRC message object and parses it for displaying
Takes an IRC message object and parses it for displaying