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.

tag_filter.rb 997B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # frozen_string_literal: true
  2. class TagFilter
  3. KEYS = %i(
  4. directory
  5. reviewed
  6. unreviewed
  7. pending_review
  8. popular
  9. active
  10. name
  11. ).freeze
  12. attr_reader :params
  13. def initialize(params)
  14. @params = params
  15. end
  16. def results
  17. scope = Tag.unscoped
  18. params.each do |key, value|
  19. next if key.to_s == 'page'
  20. scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
  21. end
  22. scope.order(id: :desc)
  23. end
  24. private
  25. def scope_for(key, value)
  26. case key.to_s
  27. when 'directory'
  28. Tag.discoverable
  29. when 'reviewed'
  30. Tag.reviewed.order(reviewed_at: :desc)
  31. when 'unreviewed'
  32. Tag.unreviewed
  33. when 'pending_review'
  34. Tag.pending_review.order(requested_review_at: :desc)
  35. when 'popular'
  36. Tag.order('max_score DESC NULLS LAST')
  37. when 'active'
  38. Tag.order('last_status_at DESC NULLS LAST')
  39. when 'name'
  40. Tag.matches_name(value)
  41. else
  42. raise "Unknown filter: #{key}"
  43. end
  44. end
  45. end