where i deviate from standard mastodon assets
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

custom_emoji_filter.rb 863B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. class CustomEmojiFilter
  3. KEYS = %i(
  4. local
  5. remote
  6. by_domain
  7. shortcode
  8. ).freeze
  9. attr_reader :params
  10. def initialize(params)
  11. @params = params
  12. end
  13. def results
  14. scope = CustomEmoji.alphabetic
  15. params.each do |key, value|
  16. next if key.to_s == 'page'
  17. scope.merge!(scope_for(key, value)) if value.present?
  18. end
  19. scope
  20. end
  21. private
  22. def scope_for(key, value)
  23. case key.to_s
  24. when 'local'
  25. CustomEmoji.local.left_joins(:category).reorder(Arel.sql('custom_emoji_categories.name ASC NULLS FIRST, custom_emojis.shortcode ASC'))
  26. when 'remote'
  27. CustomEmoji.remote
  28. when 'by_domain'
  29. CustomEmoji.where(domain: value.strip.downcase)
  30. when 'shortcode'
  31. CustomEmoji.search(value.strip)
  32. else
  33. raise "Unknown filter: #{key}"
  34. end
  35. end
  36. end