<commit_before>import React, {Component, PropTypes} from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {intlShape, injectIntl} from 'react-intl';
import Dropzone from 'react-dropzone';
import classNames from 'classnames';
import _ from 'lodash';
import autobind from 'autobind-decorator';

import {
  constructFiles
} from '@ciscospark/react-component-utils';
import {fetchAvatarForUserId} from '@ciscospark/redux-module-avatar';
import {
  acknowledgeActivityOnServer,
  createConversationWithUser,
  loadPreviousMessages,
  receiveMercuryActivity,
  receiveMercuryComment,
  updateMercuryState
} from '@ciscospark/redux-module-conversation';
import {
  fetchFlags,
  flagActivity,
  removeFlagFromServer
} from '@ciscospark/redux-module-flags';
import {
  setTyping
} from '@ciscospark/redux-module-indicators';
import {addFiles, removeInflightActivity} from '@ciscospark/redux-module-activity';
import ConfirmationModal from '@ciscospark/react-component-confirmation-modal';
import Cover from '@ciscospark/react-component-cover';
import LoadingScreen from '@ciscospark/react-component-loading-screen';
import ScrollToBottomButton from '@ciscospark/react-component-scroll-to-bottom-button';
import ActivityList from '@ciscospark/react-container-activity-list';
import MessageComposer from '@ciscospark/react-container-message-composer';
import ReadReceipts from '@ciscospark/react-container-read-receipts';
import ScrollingActivity from '@ciscospark/react-container-scrolling-activity';

import {
  NOTIFICATION_TYPE_POST,
  createNotification
} from '@ciscospark/react-container-notifications';

import {
  confirmDeleteActivity,
  deleteActivityAndDismiss,
  hideDeleteModal,
  setScrollPosition,
  showScrollToBottomButton,
  updateHasNewMessage
} from './actions';

import styles from './styles.css';
import messages from './messages';
import {constructActivityEventData} from './utils';

import events from './constants';

/**
 * MessageWidget Container
 * @extends Component
 */
export class MessageWidget extends Component {

  constructor(props) {
    super(props);
    this.handleScroll = _.debounce(this.handleScroll, 150);
  }

  componentDidMount() {
    // If our widget is instantiated with all the props loaded,
    // we can setup the conversation
    this.establishConversation(this.props);
  }

  componentWillReceiveProps(nextProps) {
    // This needs to fire here because props are loaded async via redux
    this.establishConversation(nextProps);
  }

  shouldComponentUpdate(nextProps) {
    const props = this.props;

    return nextProps.conversation !== props.conversation
      || nextProps.flags !== props.flags
      || nextProps.indicators !== props.indicators
      || nextProps.share !== props.share
      || nextProps.user !== props.user
      || nextProps.widgetMessage !== props.widgetMessage
      || nextProps.activity !== props.activity;
  }

  componentWillUpdate(nextProps) {
    const props = this.props;
    if (this.activityList && nextProps.conversation.activities.size !== props.conversation.activities.size) {
      this.scrollHeight = this.activityList.getScrollHeight();
    }
  }

  componentDidUpdate(prevProps) {
    const props = this.props;
    const activityList = this.activityList;
    if (activityList) {
      const activities = props.conversation.activities;
      const prevActivities = prevProps.conversation.activities;
      const lastActivityFromPrev = prevActivities.last();
      const lastActivityFromThis = activities.last();

      // If new activity comes in
      if (lastActivityFromPrev
        && lastActivityFromThis
        && activities.size !== prevActivities.size
        && lastActivityFromPrev.id !== lastActivityFromThis.id) {
        if (props.user.get(`currentUser`).id !== lastActivityFromThis.actor.id) {
          // Send notification of new message
          props.createNotification(lastActivityFromThis.url, NOTIFICATION_TYPE_POST);
        }
      }
      this.updateScroll(activities, prevActivities, prevProps.widgetMessage.get(`scrollPosition`).scrollTop);
      if (this.shouldScrollToBottom(props, prevProps)) {
        activityList.scrollToBottom();
      }
    }
  }

  /**
   * Check if activity list should scroll to bottom
   *
   * @param {object} props
   * @param {object} prevProps
   * @returns {boolean}
   */
  shouldScrollToBottom(props, prevProps) {
    let shouldScrollToBottom = false;
    const activityList = this.activityList;
    const lastActivityFromPrev = prevProps.conversation.activities.last();
    const lastActivityFromThis = props.conversation.activities.last();
    // If new activity comes in<commit_msg>fix(widget-message): remove empty notification of locus events<commit_after>import React, {Component, PropTypes} from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {intlShape, injectIntl} from 'react-intl';
import Dropzone from 'react-dropzone';
import classNames from 'classnames';
import _ from 'lodash';
import autobind from 'autobind-decorator';

import {
  constructFiles
} from '@ciscospark/react-component-utils';
import {fetchAvatarForUserId} from '@ciscospark/redux-module-avatar';
import {
  acknowledgeActivityOnServer,
  createConversationWithUser,
  loadPreviousMessages,
  receiveMercuryActivity,
  receiveMercuryComment,
  updateMercuryState
} from '@ciscospark/redux-module-conversation';
import {
  fetchFlags,
  flagActivity,
  removeFlagFromServer
} from '@ciscospark/redux-module-flags';
import {
  setTyping
} from '@ciscospark/redux-module-indicators';
import {addFiles, removeInflightActivity} from '@ciscospark/redux-module-activity';
import ConfirmationModal from '@ciscospark/react-component-confirmation-modal';
import Cover from '@ciscospark/react-component-cover';
import LoadingScreen from '@ciscospark/react-component-loading-screen';
import ScrollToBottomButton from '@ciscospark/react-component-scroll-to-bottom-button';
import ActivityList from '@ciscospark/react-container-activity-list';
import MessageComposer from '@ciscospark/react-container-message-composer';
import ReadReceipts from '@ciscospark/react-container-read-receipts';
import ScrollingActivity from '@ciscospark/react-container-scrolling-activity';

import {
  NOTIFICATION_TYPE_POST,
  createNotification
} from '@ciscospark/react-container-notifications';

import {
  confirmDeleteActivity,
  deleteActivityAndDismiss,
  hideDeleteModal,
  setScrollPosition,
  showScrollToBottomButton,
  updateHasNewMessage
} from './actions';

import styles from './styles.css';
import messages from './messages';
import {constructActivityEventData} from './utils';

import events from './constants';

/**
 * MessageWidget Container
 * @extends Component
 */
export class MessageWidget extends Component {

  constructor(props) {
    super(props);
    this.handleScroll = _.debounce(this.handleScroll, 150);
  }

  componentDidMount() {
    // If our widget is instantiated with all the props loaded,
    // we can setup the conversation
    this.establishConversation(this.props);
  }

  componentWillReceiveProps(nextProps) {
    // This needs to fire here because props are loaded async via redux
    this.establishConversation(nextProps);
  }

  shouldComponentUpdate(nextProps) {
    const props = this.props;

    return nextProps.conversation !== props.conversation
      || nextProps.flags !== props.flags
      || nextProps.indicators !== props.indicators
      || nextProps.share !== props.share
      || nextProps.user !== props.user
      || nextProps.widgetMessage !== props.widgetMessage
      || nextProps.activity !== props.activity;
  }

  componentWillUpdate(nextProps) {
    const props = this.props;
    if (this.activityList && nextProps.conversation.activities.size !== props.conversation.activities.size) {
      this.scrollHeight = this.activityList.getScrollHeight();
    }
  }

  componentDidUpdate(prevProps) {
    const props = this.props;
    const activityList = this.activityList;
    if (activityList) {
      const activities = props.conversation.activities;
      const prevActivities = prevProps.conversation.activities;
      const lastActivityFromPrev = prevActivities.last();
      const lastActivityFromThis = activities.last();
      const objectType = lastActivityFromThis.object ? lastActivityFromThis.object.objectType : undefined;

      // If new activity comes in
      if (lastActivityFromPrev
        && lastActivityFromThis
        && activities.size !== prevActivities.size
        && lastActivityFromPrev.id !== lastActivityFromThis.id
        && props.user.get(`currentUser`).id !== lastActivityFromThis.actor.id
        && objectType !== `locusSessionSummary`
        ) {
        // Send notification of new message
        props.createNotification(lastActivityFromThis.url, NOTIFICATION_TYPE_POST);
      }
      this.updateScroll(activities, prevActivities, prevProps.widgetMessage.get(`scrollPosition`).scrollTop);
      if (this.shouldScrollToBottom(props, prevProps)) {
        activityList.scrollToBottom();
      }
    }
  }

  /**
   * Check if activity list should scroll to bottom
   *
   * @param {object} props
   * @param {object} prevProps
   * @returns {boolean}
   */
  shouldScrollToBottom(props, prevProps) {
    let shouldScrollToBottom = false;
    const activityList = this.activityList;
    const lastActivityFromPrev = prevProps.conversation.activities.last();
    const lastActivityFromThis = props.conversation.activities.last();
    // If new activity comes in
{'fraction_non_alphanumeric': 0.10503190710325348, 'fraction_numerical': 0.0006276807197405586, 'mean_word_length': 4.334821428571429, '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': '3315553', 'n_tokens_mistral': 2708, 'n_tokens_neox': 2674, 'n_words': 585}