<commit_before>import PropTypes from 'prop-types';
import React from 'react';
import _ from 'lodash';
import UserName from './user-name';

// props types
const userType = PropTypes.shape({
  id:       PropTypes.string,
  username: PropTypes.string
});

const commentType = PropTypes.shape({ user: userType });

export default class PostVia extends React.Component {
  static propTypes = {
    post: PropTypes.shape({
      createdBy:      userType,
      recipients:     PropTypes.arrayOf(userType),
      comments:       PropTypes.arrayOf(commentType),
      usersLikedPost: PropTypes.arrayOf(userType)
    }).isRequired,

    me: PropTypes.shape({
      id:            PropTypes.string,
      subscriptions: PropTypes.arrayOf(PropTypes.string)
    }).isRequired
  };

  constructor(props) {
    super(props);
    this.state = { expanded: false };
  }

  expand = () => this.setState({ expanded: true });

  render() {
    const {
      post: {
        createdBy,
        recipients,
        comments,
        usersLikedPost
      },
      me: {
        id: myId,
        subscriptions
      }
    } = this.props;

    const isMe = ({ id }) => myId === id;
    const inSubscriptions = ({ id }) => myId === id || (subscriptions && subscriptions.some((s) => s == id));

    if (inSubscriptions(createdBy) || recipients.some(inSubscriptions)) {
      return false;
    }

    const inComments = comments.map(_.property('user')).filter(inSubscriptions);
    const inLikes = usersLikedPost.filter(inSubscriptions);

    let textPrefix = false;
    if (inComments.length === 0 && inLikes.length === 0) {
      textPrefix = 'somebody';
    } else if (inComments.some(isMe)) {
      textPrefix = 'your comment';
    } else if (inLikes.some(isMe)) {
      textPrefix = 'your like';
    }

    const users = _.unionBy(inComments, inLikes, _.property('id')).filter((u) => !isMe(u));
    const cutAt = textPrefix ? 2 : 3;
    const foldedCount = (!this.state.expanded && users.length > cutAt + 1) ? users.length - cutAt : 0;

    if (foldedCount) {
      users.length -= foldedCount;
    }

    return (
      <span className="post-via-sources">
        via {textPrefix}
        {users.map((u, i) => (<commit_msg>Skip hidden comments in PostVia calculation<commit_after>import PropTypes from 'prop-types';
import React from 'react';
import _ from 'lodash';
import UserName from './user-name';

// props types
const userType = PropTypes.shape({
  id:       PropTypes.string,
  username: PropTypes.string
});

const commentType = PropTypes.shape({ user: userType });

export default class PostVia extends React.Component {
  static propTypes = {
    post: PropTypes.shape({
      createdBy:      userType,
      recipients:     PropTypes.arrayOf(userType),
      comments:       PropTypes.arrayOf(commentType),
      usersLikedPost: PropTypes.arrayOf(userType)
    }).isRequired,

    me: PropTypes.shape({
      id:            PropTypes.string,
      subscriptions: PropTypes.arrayOf(PropTypes.string)
    }).isRequired
  };

  constructor(props) {
    super(props);
    this.state = { expanded: false };
  }

  expand = () => this.setState({ expanded: true });

  render() {
    const {
      post: {
        createdBy,
        recipients,
        comments,
        usersLikedPost
      },
      me: {
        id: myId,
        subscriptions
      }
    } = this.props;

    const isMe = ({ id }) => myId === id;
    const inSubscriptions = ({ id }) => myId === id || (subscriptions && subscriptions.some((s) => s == id));

    if (inSubscriptions(createdBy) || recipients.some(inSubscriptions)) {
      return false;
    }

    const inComments = comments.map(_.property('user')).filter(Boolean).filter(inSubscriptions);
    const inLikes = usersLikedPost.filter(inSubscriptions);

    let textPrefix = false;
    if (inComments.length === 0 && inLikes.length === 0) {
      textPrefix = 'somebody';
    } else if (inComments.some(isMe)) {
      textPrefix = 'your comment';
    } else if (inLikes.some(isMe)) {
      textPrefix = 'your like';
    }

    const users = _.unionBy(inComments, inLikes, _.property('id')).filter((u) => !isMe(u));
    const cutAt = textPrefix ? 2 : 3;
    const foldedCount = (!this.state.expanded && users.length > cutAt + 1) ? users.length - cutAt : 0;

    if (foldedCount) {
      users.length -= foldedCount;
    }

    return (
      <span className="post-via-sources">
        via {textPrefix}
        {users.map((u, i) => (
{'fraction_non_alphanumeric': 0.1395505617977528, 'fraction_numerical': 0.002696629213483146, 'mean_word_length': 2.6937759336099587, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '3598483', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1354, 'n_words': 313}