<commit_before>class PostSerializer < BasicPostSerializer

  # To pass in additional information we might need
  attr_accessor :topic_slug
  attr_accessor :topic_view
  attr_accessor :parent_post
  attr_accessor :add_raw
  attr_accessor :single_post_link_counts
  attr_accessor :draft_sequence

  attributes :post_number,
             :post_type,
             :updated_at,
             :reply_count,
             :reply_to_post_number,
             :quote_count,
             :avg_time,
             :incoming_link_count,
             :reads,
             :score,
             :yours,
             :topic_slug,
             :topic_id,
             :display_username,
             :version,
             :can_edit,
             :can_delete,
             :can_recover,
             :link_counts,
             :read,
             :user_title,
             :reply_to_user,
             :bookmarked,
             :raw,
             :actions_summary,
             :moderator?,
             :staff?,
             :user_id,
             :draft_sequence,
             :hidden,
             :hidden_reason_id,
             :deleted_at,
             :trust_level,
             :deleted_by


  def moderator?
    object.user.moderator?
  end

  def staff?
    object.user.staff?
  end

  def yours
    scope.user == object.user
  end

  def can_edit
    scope.can_edit?(object)
  end

  def can_delete
    scope.can_delete?(object)
  end

  def can_recover
    scope.can_recover_post?(object)
  end

  def display_username
    object.user.name
  end

  def link_counts
    return @single_post_link_counts if @single_post_link_counts.present?

    # TODO: This could be better, just porting the old one over
    @topic_view.link_counts[object.id].map do |link|
      result = {}
      result[:url] = link[:url]
      result[:internal] = link[:internal]
      result[:reflection] = link[:reflection]
      result[:title] = link[:title] if link[:title].present?
      result[:clicks] = link[:clicks] || 0
      result
    end
  end

  def read
    @topic_view.read?(object.post_number)
  end

  def score
    object.score || 0
  end

  def version
    object.cached_version
  end

  def user_title
    object.user.title
  end

  def trust_level
    object.user.trust_level
  end

  def reply_to_user
    {
      username: object.reply_to_user.username,
      name: object.reply_to_user.name
    }
  end

  def bookmarked
    true
  end

  def deleted_by
    BasicUserSerializer.new(object.deleted_by, root: false).as_json
  end

  def include_deleted_by?
    staff? && object.deleted_by.present?
  end

  # Summary of the actions taken on this post
  def actions_summary
    result = []
    PostActionType.types.each do |sym, id|
      next if [:bookmark].include?(sym)
      count_col = "#{sym}_count".to_sym

      count = object.send(count_col) if object.respond_to?(count_col)
      count ||= 0
      action_summary = {id: id,
                        count: count,
                        hidden: (sym == :vote),
                        can_act: scope.post_can_act?(object, sym, taken_actions: post_actions)}

      # The following only applies if you're logged in
      if action_summary[:can_act] && scope.current_user.present?
        action_summary[:can_clear_flags] = scope.is_staff? && PostActionType.flag_types.values.include?(id)
      end

      if post_actions.present? && post_actions.has_key?(id)
        action_summary[:acted] = true
        action_summary[:can_undo] = scope.can_delete?(post_actions[id])
      end
<commit_msg>FIX: deleted_by wasn't showing up on refresh<commit_after>class PostSerializer < BasicPostSerializer

  # To pass in additional information we might need
  attr_accessor :topic_slug
  attr_accessor :topic_view
  attr_accessor :parent_post
  attr_accessor :add_raw
  attr_accessor :single_post_link_counts
  attr_accessor :draft_sequence

  attributes :post_number,
             :post_type,
             :updated_at,
             :reply_count,
             :reply_to_post_number,
             :quote_count,
             :avg_time,
             :incoming_link_count,
             :reads,
             :score,
             :yours,
             :topic_slug,
             :topic_id,
             :display_username,
             :version,
             :can_edit,
             :can_delete,
             :can_recover,
             :link_counts,
             :read,
             :user_title,
             :reply_to_user,
             :bookmarked,
             :raw,
             :actions_summary,
             :moderator?,
             :staff?,
             :user_id,
             :draft_sequence,
             :hidden,
             :hidden_reason_id,
             :deleted_at,
             :trust_level,
             :deleted_by


  def moderator?
    object.user.moderator?
  end

  def staff?
    object.user.staff?
  end

  def yours
    scope.user == object.user
  end

  def can_edit
    scope.can_edit?(object)
  end

  def can_delete
    scope.can_delete?(object)
  end

  def can_recover
    scope.can_recover_post?(object)
  end

  def display_username
    object.user.name
  end

  def link_counts
    return @single_post_link_counts if @single_post_link_counts.present?

    # TODO: This could be better, just porting the old one over
    @topic_view.link_counts[object.id].map do |link|
      result = {}
      result[:url] = link[:url]
      result[:internal] = link[:internal]
      result[:reflection] = link[:reflection]
      result[:title] = link[:title] if link[:title].present?
      result[:clicks] = link[:clicks] || 0
      result
    end
  end

  def read
    @topic_view.read?(object.post_number)
  end

  def score
    object.score || 0
  end

  def version
    object.cached_version
  end

  def user_title
    object.user.title
  end

  def trust_level
    object.user.trust_level
  end

  def reply_to_user
    {
      username: object.reply_to_user.username,
      name: object.reply_to_user.name
    }
  end

  def bookmarked
    true
  end

  def deleted_by
    BasicUserSerializer.new(object.deleted_by, root: false).as_json
  end

  def include_deleted_by?
    scope.is_staff? && object.deleted_by.present?
  end

  # Summary of the actions taken on this post
  def actions_summary
    result = []
    PostActionType.types.each do |sym, id|
      next if [:bookmark].include?(sym)
      count_col = "#{sym}_count".to_sym

      count = object.send(count_col) if object.respond_to?(count_col)
      count ||= 0
      action_summary = {id: id,
                        count: count,
                        hidden: (sym == :vote),
                        can_act: scope.post_can_act?(object, sym, taken_actions: post_actions)}

      # The following only applies if you're logged in
      if action_summary[:can_act] && scope.current_user.present?
        action_summary[:can_clear_flags] = scope.is_staff? && PostActionType.flag_types.values.include?(id)
      end

      if post_actions.present? && post_actions.has_key?(id)
        action_summary[:acted] = true
        action_summary[:can_undo] = scope.can_delete?(post_actions[id])
      end

{'fraction_non_alphanumeric': 0.08633802816901408, 'fraction_numerical': 0.0008450704225352113, 'mean_word_length': 2.068712186689715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7300374', 'n_tokens_mistral': 2238, 'n_tokens_neox': 2192, 'n_words': 464}