<commit_before>angular.module('loomioApp').controller 'ThreadPageController', ($scope, $routeParams, $location, $rootScope, Records, MessageChannelService, CurrentUser, ModalService, DiscussionForm, ScrollService, AbilityService) ->
  $rootScope.$broadcast('currentComponent', { page: 'threadPage'})

  @performScroll = ->
    elementToFocus = @elementToFocus()
    if elementToFocus && !@scrolledAlready
      ScrollService.scrollTo elementToFocus
      @scrolledAlready = true

  @elementToFocus = ->
    if $location.hash().match(/^proposal-\d+$/) and Records.proposals.find(@focusedProposalId)
      "#proposal-#{@focusedProposalId}"
    else if @discussion.lastSequenceId == 0 or @sequenceIdToFocus == -1
      ".thread-context"
    else if Records.events.findByDiscussionAndSequenceId(@discussion, @sequenceIdToFocus)
      ".activity-card__last-read-activity"
    else
      false # our record isn't there yet

  @init = (discussion) =>
    if discussion and !@discussion?
      @discussion = discussion
      @group      = @discussion.group()
      @comment    = Records.comments.initialize(discussion_id: @discussion.id)

      @sequenceIdToFocus = @discussion.reader().lastReadSequenceId # or location hash when we put it back in.

      $rootScope.$broadcast 'setTitle', @discussion.title
      $rootScope.$broadcast 'viewingThread', @discussion

      MessageChannelService.subscribeTo "/discussion-#{@discussion.key}"
      @performScroll()

  @init Records.discussions.find $routeParams.key
  Records.discussions.findOrFetchByKey($routeParams.key).then @init, (error) ->
    $rootScope.$broadcast('pageError', error)

  $scope.$on 'threadPageEventsLoaded',    (event) =>
    @eventsLoaded = true<commit_msg>Ensure new comments use markdown<commit_after>angular.module('loomioApp').controller 'ThreadPageController', ($scope, $routeParams, $location, $rootScope, Records, MessageChannelService, CurrentUser, ModalService, DiscussionForm, ScrollService, AbilityService) ->
  $rootScope.$broadcast('currentComponent', { page: 'threadPage'})

  @performScroll = ->
    elementToFocus = @elementToFocus()
    if elementToFocus && !@scrolledAlready
      ScrollService.scrollTo elementToFocus
      @scrolledAlready = true

  @elementToFocus = ->
    if $location.hash().match(/^proposal-\d+$/) and Records.proposals.find(@focusedProposalId)
      "#proposal-#{@focusedProposalId}"
    else if @discussion.lastSequenceId == 0 or @sequenceIdToFocus == -1
      ".thread-context"
    else if Records.events.findByDiscussionAndSequenceId(@discussion, @sequenceIdToFocus)
      ".activity-card__last-read-activity"
    else
      false # our record isn't there yet

  @init = (discussion) =>
    if discussion and !@discussion?
      @discussion = discussion
      @group      = @discussion.group()
      @comment    = Records.comments.initialize(discussion_id: @discussion.id, uses_markdown: true)

      @sequenceIdToFocus = @discussion.reader().lastReadSequenceId # or location hash when we put it back in.

      $rootScope.$broadcast 'setTitle', @discussion.title
      $rootScope.$broadcast 'viewingThread', @discussion

      MessageChannelService.subscribeTo "/discussion-#{@discussion.key}"
      @performScroll()

  @init Records.discussions.find $routeParams.key
  Records.discussions.findOrFetchByKey($routeParams.key).then @init, (error) ->
    $rootScope.$broadcast('pageError', error)

  $scope.$on 'threadPageEventsLoaded',    (event) =>
    @eventsLoaded = true
{'fraction_non_alphanumeric': 0.12521539345203905, 'fraction_numerical': 0.0011487650775416428, 'mean_word_length': 4.350230414746544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6960398', 'n_tokens_mistral': 1032, 'n_tokens_neox': 969, 'n_words': 201}