<commit_before>import React, { PureComponent, PropTypes } from "react";
import Linkify from "react-linkify";
//import Highlighter from "react-highlight-words";

import HighlightObserver from "./HighlightObserver.jsx";
import UserLink from "./UserLink.jsx";

const linkifyProperties = { target: "_blank" };

const EMOTE_IMG_URL_ROOT = "//static-cdn.jtvnw.net/emoticons/v1/";

class ChatMessageLine extends PureComponent {

	renderEmoticon(emoteId, emoteText, emoteKey) {
		// TODO: THIS SHOULD SO MUCH BE SOME PLACE ELSE BUT SHUT IT FOR NOW

		return <img
			src={EMOTE_IMG_URL_ROOT + emoteId + "/1.0"}
			srcSet={
				EMOTE_IMG_URL_ROOT + emoteId + "/1.0 1x, " +
				EMOTE_IMG_URL_ROOT + emoteId + "/2.0 2x"
			}
			alt={emoteText}
			key={`emote-${emoteKey}`}
			/>;
	}

	renderMessage() {
		// Emoticons
		// TODO: THIS SHOULD BE SOME PLACE ELSE

		const { message, tags } = this.props;

		if (tags && tags.emotes) {
			// Find all indices and sort, return array
			var allEmotes = [];
			tags.emotes.forEach((e) => {
				if (e && e.indices) {
					e.indices.forEach((i) => {
						if (i && i.start && i.end) {
							allEmotes.push(
								{
									start: parseInt(i.start, 10),
									end: parseInt(i.end, 10),
									number: e.number
								}
							);
						}
					});
				}
			});

			allEmotes.sort((a, b) => {
				if (a && b) {
					if (a.start < b.start) { return -1; }
					if (a.start > b.start) { return 1; }
					return 0;
				}
			});

			var output = [], lastEnd = 0, msgArray = [...message];

			allEmotes.forEach((e, index) => {
				output.push(msgArray.slice(lastEnd, e.start).join(""));
				output.push(this.renderEmoticon(
					e.number, msgArray.slice(e.start, e.end + 1).join(""), index
				));
				lastEnd = e.end + 1;<commit_msg>Fixed an issue where an emote would not be rendered if it was at the beginning of a message<commit_after>import React, { PureComponent, PropTypes } from "react";
import Linkify from "react-linkify";
//import Highlighter from "react-highlight-words";

import HighlightObserver from "./HighlightObserver.jsx";
import UserLink from "./UserLink.jsx";

const linkifyProperties = { target: "_blank" };

const EMOTE_IMG_URL_ROOT = "//static-cdn.jtvnw.net/emoticons/v1/";

class ChatMessageLine extends PureComponent {

	renderEmoticon(emoteId, emoteText, emoteKey) {
		// TODO: THIS SHOULD SO MUCH BE SOME PLACE ELSE BUT SHUT IT FOR NOW

		return <img
			src={EMOTE_IMG_URL_ROOT + emoteId + "/1.0"}
			srcSet={
				EMOTE_IMG_URL_ROOT + emoteId + "/1.0 1x, " +
				EMOTE_IMG_URL_ROOT + emoteId + "/2.0 2x"
			}
			alt={emoteText}
			key={`emote-${emoteKey}`}
			/>;
	}

	renderMessage() {
		// Emoticons
		// TODO: THIS SHOULD BE SOME PLACE ELSE

		const { message, tags } = this.props;

		if (tags && tags.emotes) {
			// Find all indices and sort, return array
			var allEmotes = [];
			tags.emotes.forEach((e) => {
				if (e && e.indices) {
					e.indices.forEach((i) => {
						if (i) {
							const start = parseInt(i.start, 10);
							const end = parseInt(i.end, 10);

							if (!isNaN(start) && !isNaN(end)) {
								allEmotes.push(
									{
										start,
										end,
										number: e.number
									}
								);
							}
						}
					});
				}
			});

			allEmotes.sort((a, b) => {
				if (a && b) {
					if (a.start < b.start) { return -1; }
					if (a.start > b.start) { return 1; }
					return 0;
				}
			});

			var output = [], lastEnd = 0, msgArray = [...message];

			allEmotes.forEach((e, index) => {
				output.push(msgArray.slice(lastEnd, e.start).join(""));
				output.push(this.renderEmoticon(
					e.number, msgArray.slice(e.start, e.end + 1).join(""), index
				));
				lastEnd = e.end + 1;
{'fraction_non_alphanumeric': 0.15752308527973927, 'fraction_numerical': 0.010320478001086366, 'mean_word_length': 2.5311601150527325, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '2263828', 'n_tokens_mistral': 1722, 'n_tokens_neox': 1325, 'n_words': 312}