logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

custom_emoji_filter.rb (617B)


  1. # frozen_string_literal: true
  2. class CustomEmojiFilter
  3. attr_reader :params
  4. def initialize(params)
  5. @params = params
  6. end
  7. def results
  8. scope = CustomEmoji.alphabetic
  9. params.each do |key, value|
  10. scope.merge!(scope_for(key, value)) if value.present?
  11. end
  12. scope
  13. end
  14. private
  15. def scope_for(key, value)
  16. case key.to_s
  17. when 'local'
  18. CustomEmoji.local
  19. when 'remote'
  20. CustomEmoji.remote
  21. when 'by_domain'
  22. CustomEmoji.where(domain: value)
  23. when 'shortcode'
  24. CustomEmoji.search(value)
  25. else
  26. raise "Unknown filter: #{key}"
  27. end
  28. end
  29. end