<commit_before>module Messages
  class AssetContext
    attr_reader :asset, :notification_name
    def initialize(asset, name)
      @asset = asset
      @notification_name = name
    end

    def from_name
      return nil unless has_named_source?
      anonymized_user
    end

    def reply_to_name
      return nil unless has_named_source?
      I18n.t(:reply_from_name, "%{name} via Canvas Notifications", name: from_name)
    end

    private

    def anonymized_user
      if is_anonymized_asset?
        asset.can_read_author?(asset.recipient, nil) ? source_user.short_name : I18n.t(:anonymous_user, 'Anonymous User')
      else
        source_user.short_name
      end
    end

    def source_user
      if is_author_asset?
        asset.author
      elsif is_user_asset?
        asset.user
      end
    end

    def has_named_source?
      is_author_asset? || is_user_asset?
    end

    SOURCE_AUTHOR_NOTIFICATIONS = [
      "Conversation Message",
      "Submission Comment",
      "Submission Comment For Teacher"
    ]

    SOURCE_USER_NOTIFICATIONS = [
      "New Discussion Entry",
      "Assignment Submitted",
      "Assignment Resubmitted"
    ]

    ANONYMIZED_NOTIFICATIONS = [
      "Submission Comment"
    ]

    def is_anonymized_asset?
      ANONYMIZED_NOTIFICATIONS.include?(notification_name) && asset.respond_to?(:recipient)
    end

    def is_author_asset?
      SOURCE_AUTHOR_NOTIFICATIONS.include?(notification_name)
    end

    def is_user_asset?
      SOURCE_USER_NOTIFICATIONS.include?(notification_name)
    end

  end
end
<commit_msg>truncate user names in to/from fields on messages<commit_after>module Messages
  class AssetContext
    attr_reader :asset, :notification_name
    def initialize(asset, name)
      @asset = asset
      @notification_name = name
    end

    def from_name
      return nil unless has_named_source?
      CanvasTextHelper.truncate_text(anonymized_user_name, :max_length => 50)
    end

    def reply_to_name
      return nil unless has_named_source?
      I18n.t(:reply_from_name, "%{name} via Canvas Notifications", name: from_name)
    end

    private

    def anonymized_user_name
      if is_anonymized_asset?
        asset.can_read_author?(asset.recipient, nil) ? source_user.short_name : I18n.t(:anonymous_user, 'Anonymous User')
      else
        source_user.short_name
      end
    end

    def source_user
      if is_author_asset?
        asset.author
      elsif is_user_asset?
        asset.user
      end
    end

    def has_named_source?
      is_author_asset? || is_user_asset?
    end

    SOURCE_AUTHOR_NOTIFICATIONS = [
      "Conversation Message",
      "Submission Comment",
      "Submission Comment For Teacher"
    ]

    SOURCE_USER_NOTIFICATIONS = [
      "New Discussion Entry",
      "Assignment Submitted",
      "Assignment Resubmitted"
    ]

    ANONYMIZED_NOTIFICATIONS = [
      "Submission Comment"
    ]

    def is_anonymized_asset?
      ANONYMIZED_NOTIFICATIONS.include?(notification_name) && asset.respond_to?(:recipient)
    end

    def is_author_asset?
      SOURCE_AUTHOR_NOTIFICATIONS.include?(notification_name)
    end

    def is_user_asset?
      SOURCE_USER_NOTIFICATIONS.include?(notification_name)
    end

  end
end

{'fraction_non_alphanumeric': 0.06594761171032358, 'fraction_numerical': 0.0030816640986132513, 'mean_word_length': 2.8053927315357563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2538876', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1025, 'n_words': 213}