<commit_before>import { Components, registerComponent, withEdit } from 'meteor/vulcan:core';
import React, { Component } from 'react';
import { FormattedMessage } from 'meteor/vulcan:i18n';
import { Comments } from "../../lib/collections/comments";
import { shallowEqual, shallowEqualExcept } from '../../lib/modules/utils/componentUtils';
import { Posts } from '../../lib/collections/posts';
import withGlobalKeydown from '../common/withGlobalKeydown';

class CommentsList extends Component {
  state = { expandAllThreads: false }

  handleKeyDown = (event) => {
    const F_Key = 70
    if ((event.metaKey || event.ctrlKey) && event.keyCode == F_Key) {
      this.setState({expandAllThreads: true});
    }
  }

  componentDidMount() {
    const { addKeydownListener } = this.props
    addKeydownListener(this.handleKeyDown);
  }

  shouldComponentUpdate(nextProps, nextState) {
    if(!shallowEqual(this.state, nextState))
      return true;
    
    if(!shallowEqualExcept(this.props, nextProps,
      ["post","comments","editMutation","updateComment"]))
    {
      return true;
    }
    
    if(this.props.post==null || nextProps.post==null || this.props.post._id != nextProps.post._id || 
      (this.props.post.contents && this.props.post.contents.version !== nextProps.post.contents && nextProps.post.contents.version))
      return true;
    
    if(this.commentTreesDiffer(this.props.comments, nextProps.comments))
      return true;
    return false;
  }

  commentTreesDiffer(oldComments, newComments) {
    if(oldComments===null && newComments!==null) return true;
    if(oldComments!==null && newComments===null) return true;
    if(newComments===null) return false;

    if(oldComments.length != newComments.length)
      return true;
    for(let i=0; i<oldComments.length; i++) {
      if(oldComments[i].item != newComments[i].item)
        return true;
      if(this.commentTreesDiffer(oldComments[i].children, newComments[i].children))
        return true;
    }
    return false;
  }

  render() {
    const { comments, currentUser, highlightDate, editMutation, post, postPage, totalComments, condensed, startThreadTruncated, parentAnswerId, defaultNestingLevel = 1, hideReadComments, lastCommentId } = this.props;

    const { expandAllThreads } = this.state
    const { lastVisitedAt } = post
    const lastCommentedAt = Posts.getLastCommentedAt(post)
    const unreadComments = lastVisitedAt < lastCommentedAt;

    if (comments) {
      return (
        <Components.ErrorBoundary>
          <div>
            {comments.map(comment =>
              <Components.CommentsNode
                startThreadTruncated={startThreadTruncated || totalComments >= 50}
                expandAllThreads={expandAllThreads}
                unreadComments={unreadComments}
                currentUser={currentUser}
                comment={comment.item}
                nestingLevel={defaultNestingLevel}
                lastCommentId={lastCommentId}
                //eslint-disable-next-line react/no-children-prop
                children={comment.children}
                key={comment.item._id}
                highlightDate={highlightDate}
                editMutation={editMutation}
                post={post}
                postPage={postPage}
                parentAnswerId={parentAnswerId}
                condensed={condensed}
                hideReadComments={hideReadComments}
                shortform={post.shortform}
                child={defaultNestingLevel > 1}
              />)
            }
          </div>
        </Components.ErrorBoundary>
      )
    } else {
      return (
        <div>
          <p>
            <FormattedMessage id="comments.no_comments"/>
          </p>
        </div>
      )
    }
  }
}


CommentsList.displayName = "CommentsList";

const withEditOptions = {
  collection: Comments,
  fragmentName: 'CommentsList',
};


registerComponent('CommentsList', CommentsList, [withEdit, withEditOptions], withGlobalKeydown);
<commit_msg>raise limit to 100<commit_after>import { Components, registerComponent, withEdit } from 'meteor/vulcan:core';
import React, { Component } from 'react';
import { FormattedMessage } from 'meteor/vulcan:i18n';
import { Comments } from "../../lib/collections/comments";
import { shallowEqual, shallowEqualExcept } from '../../lib/modules/utils/componentUtils';
import { Posts } from '../../lib/collections/posts';
import withGlobalKeydown from '../common/withGlobalKeydown';

class CommentsList extends Component {
  state = { expandAllThreads: false }

  handleKeyDown = (event) => {
    const F_Key = 70
    if ((event.metaKey || event.ctrlKey) && event.keyCode == F_Key) {
      this.setState({expandAllThreads: true});
    }
  }

  componentDidMount() {
    const { addKeydownListener } = this.props
    addKeydownListener(this.handleKeyDown);
  }

  shouldComponentUpdate(nextProps, nextState) {
    if(!shallowEqual(this.state, nextState))
      return true;
    
    if(!shallowEqualExcept(this.props, nextProps,
      ["post","comments","editMutation","updateComment"]))
    {
      return true;
    }
    
    if(this.props.post==null || nextProps.post==null || this.props.post._id != nextProps.post._id || 
      (this.props.post.contents && this.props.post.contents.version !== nextProps.post.contents && nextProps.post.contents.version))
      return true;
    
    if(this.commentTreesDiffer(this.props.comments, nextProps.comments))
      return true;
    return false;
  }

  commentTreesDiffer(oldComments, newComments) {
    if(oldComments===null && newComments!==null) return true;
    if(oldComments!==null && newComments===null) return true;
    if(newComments===null) return false;

    if(oldComments.length != newComments.length)
      return true;
    for(let i=0; i<oldComments.length; i++) {
      if(oldComments[i].item != newComments[i].item)
        return true;
      if(this.commentTreesDiffer(oldComments[i].children, newComments[i].children))
        return true;
    }
    return false;
  }

  render() {
    const { comments, currentUser, highlightDate, editMutation, post, postPage, totalComments, condensed, startThreadTruncated, parentAnswerId, defaultNestingLevel = 1, hideReadComments, lastCommentId } = this.props;

    const { expandAllThreads } = this.state
    const { lastVisitedAt } = post
    const lastCommentedAt = Posts.getLastCommentedAt(post)
    const unreadComments = lastVisitedAt < lastCommentedAt;

    if (comments) {
      return (
        <Components.ErrorBoundary>
          <div>
            {comments.map(comment =>
              <Components.CommentsNode
                startThreadTruncated={startThreadTruncated || totalComments >= 100}
                expandAllThreads={expandAllThreads}
                unreadComments={unreadComments}
                currentUser={currentUser}
                comment={comment.item}
                nestingLevel={defaultNestingLevel}
                lastCommentId={lastCommentId}
                //eslint-disable-next-line react/no-children-prop
                children={comment.children}
                key={comment.item._id}
                highlightDate={highlightDate}
                editMutation={editMutation}
                post={post}
                postPage={postPage}
                parentAnswerId={parentAnswerId}
                condensed={condensed}
                hideReadComments={hideReadComments}
                shortform={post.shortform}
                child={defaultNestingLevel > 1}
              />)
            }
          </div>
        </Components.ErrorBoundary>
      )
    } else {
      return (
        <div>
          <p>
            <FormattedMessage id="comments.no_comments"/>
          </p>
        </div>
      )
    }
  }
}


CommentsList.displayName = "CommentsList";

const withEditOptions = {
  collection: Comments,
  fragmentName: 'CommentsList',
};


registerComponent('CommentsList', CommentsList, [withEdit, withEditOptions], withGlobalKeydown);

{'fraction_non_alphanumeric': 0.11848697394789579, 'fraction_numerical': 0.0027555110220440883, 'mean_word_length': 2.6763351749539597, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, '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': '4640096', 'n_tokens_mistral': 2362, 'n_tokens_neox': 2209, 'n_words': 397}