<commit_before>import React, { PropTypes } from 'react'
import { Link } from 'react-router'
import { regionItemsForNotifications } from '../regions/RegionRenderables'
import { Notification } from './Notification'

// HELPERS
function getActivityPath(user, post) {
  if (!user) { return '/' }
  if (!post) { return `/${user.username}` }
  return `/${user.username}/post/${post.token}`
}

function parseSummary(post, path, assets) {
  return regionItemsForNotifications(post.summary, path, assets)
}

function parseSummaryForCommentNotification(post, comment, path, assets) {
  const postContent = post && post.summary ? post.summary : []
  const commentContent = comment && comment.summary ? comment.summary : []
  const divider = [{ kind: 'rule' }]
  const combined = postContent.concat(divider, commentContent)
  return regionItemsForNotifications(combined, path, assets)
}

const UserTextLink = ({ user }) => {
  if (!user) { return null }
  return (
    <Link to={getActivityPath(user)}>
      {`@${user.username}`}
    </Link>
  )
}
UserTextLink.propTypes = {
  user: PropTypes.object,
}

const PostTextLink = ({ author, post, text = 'post' }) => {
  if (!post || !author) { return <span>{text}</span> }
  return (
    <Link to={getActivityPath(author, post)}>
      {text}
    </Link>
  )
}
PostTextLink.propTypes = {
  author: PropTypes.object,
  post: PropTypes.object,
  text: PropTypes.string,
}

// COMMENTS
export const CommentNotification = (props) => {
  const { assets, author, comment, createdAt, parentPost, parentPostAuthor } = props
  const activityPath = getActivityPath(parentPostAuthor, parentPost)
  const summary = parseSummaryForCommentNotification(parentPost, comment, activityPath, assets)
  return (
    <Notification
      activityPath={activityPath}
      className="CommentNotification"
      createdAt={createdAt}
      notifier={author}
      summary={summary}
    >
      <p>
        <UserTextLink user={author} />
        {' commented on your '}
        <PostTextLink author={author} post={parentPost} />
        {'.'}
      </p>
    </Notification>
  )
}
CommentNotification.propTypes = {
  assets: PropTypes.object,
  author: PropTypes.object,
  comment: PropTypes.object,
  createdAt: PropTypes.string,
  parentPost: PropTypes.object,
  parentPostAuthor: PropTypes.object,
}

export const CommentMentionNotification = (props) => {
  const { assets, author, comment, createdAt, parentPost, parentPostAuthor } = props
  const activityPath = getActivityPath(parentPostAuthor, parentPost)
  const summary = parseSummaryForCommentNotification(parentPost, comment, activityPath, assets)
  return (
    <Notification
      activityPath={activityPath}
      className="CommentMentionNotification"
      createdAt={createdAt}
      notifier={author}
      summary={summary}
    >
      <p>
        <UserTextLink user={author} />
        {' mentioned you in a '}
        <PostTextLink author={author} post={parentPost} text="comment" />
        {'.'}
      </p>
    </Notification>
  )
}
CommentMentionNotification.propTypes = {
  assets: PropTypes.object,
  author: PropTypes.object,
  comment: PropTypes.object,
  createdAt: PropTypes.string,
  parentPost: PropTypes.object,
  parentPostAuthor: PropTypes.object,
}

export const CommentOnOriginalPostNotification = (props) => {
  const { assets, author, comment, createdAt, repost, repostAuthor,
    repostedSource, repostedSourceAuthor } = props
  const activityPath = getActivityPath(author, repostedSource)
  const summary = parseSummaryForCommentNotification(repostedSource, comment, activityPath, assets)<commit_msg>Use the correct author for comment notifications.<commit_after>import React, { PropTypes } from 'react'
import { Link } from 'react-router'
import { regionItemsForNotifications } from '../regions/RegionRenderables'
import { Notification } from './Notification'

// HELPERS
function getActivityPath(user, post) {
  if (!user) { return '/' }
  if (!post) { return `/${user.username}` }
  return `/${user.username}/post/${post.token}`
}

function parseSummary(post, path, assets) {
  return regionItemsForNotifications(post.summary, path, assets)
}

function parseSummaryForCommentNotification(post, comment, path, assets) {
  const postContent = post && post.summary ? post.summary : []
  const commentContent = comment && comment.summary ? comment.summary : []
  const divider = [{ kind: 'rule' }]
  const combined = postContent.concat(divider, commentContent)
  return regionItemsForNotifications(combined, path, assets)
}

const UserTextLink = ({ user }) => {
  if (!user) { return null }
  return (
    <Link to={getActivityPath(user)}>
      {`@${user.username}`}
    </Link>
  )
}
UserTextLink.propTypes = {
  user: PropTypes.object,
}

const PostTextLink = ({ author, post, text = 'post' }) => {
  if (!post || !author) { return <span>{text}</span> }
  return (
    <Link to={getActivityPath(author, post)}>
      {text}
    </Link>
  )
}
PostTextLink.propTypes = {
  author: PropTypes.object,
  post: PropTypes.object,
  text: PropTypes.string,
}

// COMMENTS
export const CommentNotification = (props) => {
  const { assets, author, comment, createdAt, parentPost, parentPostAuthor } = props
  const activityPath = getActivityPath(parentPostAuthor, parentPost)
  const summary = parseSummaryForCommentNotification(parentPost, comment, activityPath, assets)
  return (
    <Notification
      activityPath={activityPath}
      className="CommentNotification"
      createdAt={createdAt}
      notifier={author}
      summary={summary}
    >
      <p>
        <UserTextLink user={author} />
        {' commented on your '}
        <PostTextLink author={parentPostAuthor} post={parentPost} />
        {'.'}
      </p>
    </Notification>
  )
}
CommentNotification.propTypes = {
  assets: PropTypes.object,
  author: PropTypes.object,
  comment: PropTypes.object,
  createdAt: PropTypes.string,
  parentPost: PropTypes.object,
  parentPostAuthor: PropTypes.object,
}

export const CommentMentionNotification = (props) => {
  const { assets, author, comment, createdAt, parentPost, parentPostAuthor } = props
  const activityPath = getActivityPath(parentPostAuthor, parentPost)
  const summary = parseSummaryForCommentNotification(parentPost, comment, activityPath, assets)
  return (
    <Notification
      activityPath={activityPath}
      className="CommentMentionNotification"
      createdAt={createdAt}
      notifier={author}
      summary={summary}
    >
      <p>
        <UserTextLink user={author} />
        {' mentioned you in a '}
        <PostTextLink author={parentPostAuthor} post={parentPost} text="comment" />
        {'.'}
      </p>
    </Notification>
  )
}
CommentMentionNotification.propTypes = {
  assets: PropTypes.object,
  author: PropTypes.object,
  comment: PropTypes.object,
  createdAt: PropTypes.string,
  parentPost: PropTypes.object,
  parentPostAuthor: PropTypes.object,
}

export const CommentOnOriginalPostNotification = (props) => {
  const { assets, author, comment, createdAt, repost, repostAuthor,
    repostedSource, repostedSourceAuthor } = props
  const activityPath = getActivityPath(author, repostedSource)
  const summary = parseSummaryForCommentNotification(repostedSource, comment, activityPath, assets)
{'fraction_non_alphanumeric': 0.12307056229327454, 'fraction_numerical': 0.0, 'mean_word_length': 4.1105633802816905, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 49, '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': '2138509', 'n_tokens_mistral': 2062, 'n_tokens_neox': 2097, 'n_words': 479}