<commit_before>module Maia
  class Message
    MAX_TOKENS_AT_ONCE = 999

    def send_to(pushable)
      devices =
        case pushable
        when ActiveRecord::Relation
          Device.owned_by pushable
        when ActiveRecord::Base
          pushable.devices
        else
          raise ArgumentError.new
        end

      enqueue devices, to_h
    end

    def enqueue(devices, payload)
      devices.pluck(:token).each_slice(MAX_TOKENS_AT_ONCE) do |tokens|
        Maia::Messenger.perform_later tokens, payload.deep_stringify_keys
      end
    end

    def alert
      ''
    end

    def badge
    end

    def sound
      'default'
    end

    def other
      {}
    end

    def priority
    end

    def content_available?
      false
    end

    def dry_run?
      false
    end

    def to_h
      hash = {
        data: other,
        priority: priority.to_s,
        notification: {
          title: alert,
          body: alert,
          sound: sound,
          badge: badge
        }.compact
      }

      hash.merge!(priority: priority) if priority
      hash.merge!(dry_run: true) if dry_run?<commit_msg>Remove priority from to_h, merge it later if it's set<commit_after>module Maia
  class Message
    MAX_TOKENS_AT_ONCE = 999

    def send_to(pushable)
      devices =
        case pushable
        when ActiveRecord::Relation
          Device.owned_by pushable
        when ActiveRecord::Base
          pushable.devices
        else
          raise ArgumentError.new
        end

      enqueue devices, to_h
    end

    def enqueue(devices, payload)
      devices.pluck(:token).each_slice(MAX_TOKENS_AT_ONCE) do |tokens|
        Maia::Messenger.perform_later tokens, payload.deep_stringify_keys
      end
    end

    def alert
      ''
    end

    def badge
    end

    def sound
      'default'
    end

    def other
      {}
    end

    def priority
    end

    def content_available?
      false
    end

    def dry_run?
      false
    end

    def to_h
      hash = {
        data: other,
        notification: {
          title: alert,
          body: alert,
          sound: sound,
          badge: badge
        }.compact
      }

      hash.merge!(priority: priority) if priority
      hash.merge!(dry_run: true) if dry_run?
{'fraction_non_alphanumeric': 0.061152661680598325, 'fraction_numerical': 0.0026396832380114386, 'mean_word_length': 1.672150411280846, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1832618', 'n_tokens_mistral': 711, 'n_tokens_neox': 667, 'n_words': 178}