<commit_before>###
#    Copyright 2015-2018 ppy Pty. Ltd.
#
#    This file is part of osu!web. osu!web is distributed with the hope of
#    attracting more community contributions to the core ecosystem of osu!.
#
#    osu!web is free software: you can redistribute it and/or modify
#    it under the terms of the Affero GNU General Public License version 3
#    as published by the Free Software Foundation.
#
#    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
#    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#    See the GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
###

{a, button, div, span, textarea} = ReactDOMFactories

el = React.createElement

deletedUser = username: osu.trans('users.deleted')

class @Comment extends React.PureComponent
  MAX_DEPTH = 3

  constructor: (props) ->
    super props

    @state =
      editing: false
      showNewReply: false
      showReplies: !@isDeleted()


  render: =>
    children = @props.commentsByParentId[@props.comment.id] ? []
    user = @userFor(@props.comment)

    repliesClass = 'comment__replies'
    repliesClass += ' comment__replies--indented' if @props.depth < MAX_DEPTH
    repliesClass += ' comment__replies--hidden' if !@state.showReplies

    div
      className: osu.classWithModifiers 'comment', @props.modifiers

      if @props.depth == 0 && @state.showReplies && children.length > 0
        div className: 'comment__line'

      div className: "comment__main #{if @isDeleted() then 'comment__main--deleted' else ''}",
        if user.id?
          a
            className: 'comment__avatar js-usercard'
            'data-user-id': user.id
            href: laroute.route('users.show', user: user.id)
            el UserAvatar, user: user, modifiers: ['full-circle']
        else
          span
            className: 'comment__avatar'
            el UserAvatar, user: user, modifiers: ['full-circle']
        div className: 'comment__container',
          div className: 'comment__row',
            if user.id?
              a
                className: 'comment__row-item comment__row-item--username comment__row-item--username-link js-usercard'
                'data-user-id': user.id
                href: laroute.route('users.show', user: user.id)
                user.username
            else
              span
                className: 'comment__row-item comment__row-item--username'
                user.username

            if @props.parent?
              message =
                if @props.parent.deleted_at?
                  osu.trans('comments.deleted')
                else
                  _.truncate $(@props.parent.message_html).text(), length: 100
              div
                className: 'comment__row-item comment__row-item--parent'
                title: message
                span className: 'fas fa-reply'
                ' '
                @userFor(@props.parent).username

            span
              className: 'comment__row-item'
              dangerouslySetInnerHTML: __html: osu.timeago(@props.comment.created_at)
          if @state.editing
            div className: 'comment__editor',
              el CommentEditor,
                id: @props.comment.id
                message: @props.comment.message
                modifiers: @props.modifiers
                close: @closeEdit
          else
            div className: 'comment__content',
              if @isDeleted() && !@props.comment.message_html?
                div className: 'comment__deleted',
                  osu.trans('comments.deleted')

              else
                div
                  className: 'comment__message'
                  dangerouslySetInnerHTML:
                    __html: @props.comment.message_html

          div className: 'comment__row comment__row--footer',
            div className: 'comment__row-item',
              button
                type: 'button'
                className: "comment__action #{if @state.showNewReply then 'comment__action--active' else ''}"
                onClick: @toggleNewReply
                osu.trans('common.buttons.reply')

            if @canEdit()
              div className: 'comment__row-item',
                button<commit_msg>Hide reply button for deleted post<commit_after>###
#    Copyright 2015-2018 ppy Pty. Ltd.
#
#    This file is part of osu!web. osu!web is distributed with the hope of
#    attracting more community contributions to the core ecosystem of osu!.
#
#    osu!web is free software: you can redistribute it and/or modify
#    it under the terms of the Affero GNU General Public License version 3
#    as published by the Free Software Foundation.
#
#    osu!web is distributed WITHOUT ANY WARRANTY; without even the implied
#    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#    See the GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with osu!web.  If not, see <http://www.gnu.org/licenses/>.
###

{a, button, div, span, textarea} = ReactDOMFactories

el = React.createElement

deletedUser = username: osu.trans('users.deleted')

class @Comment extends React.PureComponent
  MAX_DEPTH = 3

  constructor: (props) ->
    super props

    @state =
      editing: false
      showNewReply: false
      showReplies: !@isDeleted()


  render: =>
    children = @props.commentsByParentId[@props.comment.id] ? []
    user = @userFor(@props.comment)

    repliesClass = 'comment__replies'
    repliesClass += ' comment__replies--indented' if @props.depth < MAX_DEPTH
    repliesClass += ' comment__replies--hidden' if !@state.showReplies

    div
      className: osu.classWithModifiers 'comment', @props.modifiers

      if @props.depth == 0 && @state.showReplies && children.length > 0
        div className: 'comment__line'

      div className: "comment__main #{if @isDeleted() then 'comment__main--deleted' else ''}",
        if user.id?
          a
            className: 'comment__avatar js-usercard'
            'data-user-id': user.id
            href: laroute.route('users.show', user: user.id)
            el UserAvatar, user: user, modifiers: ['full-circle']
        else
          span
            className: 'comment__avatar'
            el UserAvatar, user: user, modifiers: ['full-circle']
        div className: 'comment__container',
          div className: 'comment__row',
            if user.id?
              a
                className: 'comment__row-item comment__row-item--username comment__row-item--username-link js-usercard'
                'data-user-id': user.id
                href: laroute.route('users.show', user: user.id)
                user.username
            else
              span
                className: 'comment__row-item comment__row-item--username'
                user.username

            if @props.parent?
              message =
                if @props.parent.deleted_at?
                  osu.trans('comments.deleted')
                else
                  _.truncate $(@props.parent.message_html).text(), length: 100
              div
                className: 'comment__row-item comment__row-item--parent'
                title: message
                span className: 'fas fa-reply'
                ' '
                @userFor(@props.parent).username

            span
              className: 'comment__row-item'
              dangerouslySetInnerHTML: __html: osu.timeago(@props.comment.created_at)
          if @state.editing
            div className: 'comment__editor',
              el CommentEditor,
                id: @props.comment.id
                message: @props.comment.message
                modifiers: @props.modifiers
                close: @closeEdit
          else
            div className: 'comment__content',
              if @isDeleted() && !@props.comment.message_html?
                div className: 'comment__deleted',
                  osu.trans('comments.deleted')

              else
                div
                  className: 'comment__message'
                  dangerouslySetInnerHTML:
                    __html: @props.comment.message_html

          div className: 'comment__row comment__row--footer',
            if !@isDeleted()
              div className: 'comment__row-item',
                button
                  type: 'button'
                  className: "comment__action #{if @state.showNewReply then 'comment__action--active' else ''}"
                  onClick: @toggleNewReply
                  osu.trans('common.buttons.reply')

            if @canEdit()
              div className: 'comment__row-item',
                button
{'fraction_non_alphanumeric': 0.09346005883684091, 'fraction_numerical': 0.0033944331296673455, 'mean_word_length': 1.9075657894736842, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6717058', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2316, 'n_words': 638}