<commit_before>import React, { PureComponent } from "react";
import PropTypes from "prop-types";
import { findDOMNode } from "react-dom";
import remove from "lodash/remove";
import values from "lodash/values";
import "intersection-observer";

import ChatLines from "./ChatLines.jsx";
import { PAGE_TYPES, PAGE_TYPE_NAMES } from "../constants";
import { reportHighlightAsSeen } from "../lib/io";
import {
	areWeScrolledToTheBottom, scrollToTheBottom, scrollToTheTop
} from "../lib/visualBehavior";

const FLASHING_LINE_CLASS_NAME = "flashing";

class ChatFrame extends PureComponent {
	constructor(props) {
		super(props);

		this.lineObserverCallback = this.lineObserverCallback.bind(this);
		this.onObserve = this.onObserve.bind(this);
		this.onUnobserve = this.onUnobserve.bind(this);

		this.observerHandlers = {
			observe: this.onObserve,
			unobserve: this.onUnobserve
		};

		this.atBottom = true;

		this.clearObserver();
	}

	componentDidMount() {
		let { lines, logDate } = this.props;

		if (lines && lines.length && !logDate) {
			scrollToTheBottom();
		}
	}

	componentWillReceiveProps(newProps) {
		const {
			lines,
			logDate,
			pageQuery,
			pageType
		} = newProps;

		const {
			lines: oldLines,
			logDate: oldLogDate,
			pageQuery: oldQuery,
			pageType: oldType
		} = this.props;

		// Lines change

		if (
			lines !== oldLines &&
			pageQuery === oldQuery &&
			pageType === oldType &&
			logDate === oldLogDate
		) {
			this.atBottom = areWeScrolledToTheBottom();
		}
	}

	componentDidUpdate(oldProps) {
		const {
			inFocus,
			lines,
			logBrowserOpen,
			logDate,
			pageQuery,
			pageType,
			selectedLine,
			userListOpen
		} = this.props;

		const {
			inFocus: oldInFocus,
			lines: oldLines,
			logDate: oldLogDate,
			logBrowserOpen: oldLogBrowserOpen,
			pageQuery: oldQuery,
			pageType: oldType,
			selectedLine: oldSelectedLine,
			userListOpen: oldUserListOpen
		} = oldProps;

		// Page changed

		let pageChanged = (
			pageQuery !== oldQuery ||
			pageType !== oldType ||
			logDate !== oldLogDate
		);

		if (pageChanged) {
			this.clearObserver();
		}

		// Lines changed

		if (lines !== oldLines) {
			if (logDate) {
				scrollToTheTop();
			}
			else if (this.atBottom || pageChanged) {
				scrollToTheBottom();
			}
		}

		// User list opened

		if (
			userListOpen &&<commit_msg>Fixed issue where chat would not auto scroll after a new offline message was posted<commit_after>import React, { PureComponent } from "react";
import PropTypes from "prop-types";
import { findDOMNode } from "react-dom";
import remove from "lodash/remove";
import values from "lodash/values";
import "intersection-observer";

import ChatLines from "./ChatLines.jsx";
import { PAGE_TYPES, PAGE_TYPE_NAMES } from "../constants";
import { reportHighlightAsSeen } from "../lib/io";
import {
	areWeScrolledToTheBottom, scrollToTheBottom, scrollToTheTop
} from "../lib/visualBehavior";

const FLASHING_LINE_CLASS_NAME = "flashing";

class ChatFrame extends PureComponent {
	constructor(props) {
		super(props);

		this.lineObserverCallback = this.lineObserverCallback.bind(this);
		this.onObserve = this.onObserve.bind(this);
		this.onUnobserve = this.onUnobserve.bind(this);

		this.observerHandlers = {
			observe: this.onObserve,
			unobserve: this.onUnobserve
		};

		this.atBottom = true;

		this.clearObserver();
	}

	componentDidMount() {
		let { lines, logDate } = this.props;

		if (lines && lines.length && !logDate) {
			scrollToTheBottom();
		}
	}

	componentWillReceiveProps(newProps) {
		const {
			lines,
			logDate,
			pageQuery,
			pageType
		} = newProps;

		const {
			lines: oldLines,
			logDate: oldLogDate,
			pageQuery: oldQuery,
			pageType: oldType
		} = this.props;

		// Lines change

		if (
			lines !== oldLines &&
			pageQuery === oldQuery &&
			pageType === oldType &&
			logDate === oldLogDate
		) {
			this.atBottom = areWeScrolledToTheBottom();
		}
	}

	componentDidUpdate(oldProps) {
		const {
			inFocus,
			lines,
			logBrowserOpen,
			logDate,
			offlineMessages,
			pageQuery,
			pageType,
			selectedLine,
			userListOpen
		} = this.props;

		const {
			inFocus: oldInFocus,
			lines: oldLines,
			logDate: oldLogDate,
			logBrowserOpen: oldLogBrowserOpen,
			offlineMessages: oldOfflineMessages,
			pageQuery: oldQuery,
			pageType: oldType,
			selectedLine: oldSelectedLine,
			userListOpen: oldUserListOpen
		} = oldProps;

		// Page changed

		let pageChanged = (
			pageQuery !== oldQuery ||
			pageType !== oldType ||
			logDate !== oldLogDate
		);

		if (pageChanged) {
			this.clearObserver();
		}

		// Lines changed

		if (lines !== oldLines || offlineMessages !== oldOfflineMessages) {
			if (logDate) {
				scrollToTheTop();
			}
			else if (this.atBottom || pageChanged) {
				scrollToTheBottom();
			}
		}

		// User list opened

		if (
			userListOpen &&
{'fraction_non_alphanumeric': 0.11879139072847682, 'fraction_numerical': 0.0, 'mean_word_length': 3.5252808988764044, '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': '5199684', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1585, 'n_words': 349}