* Add trending statuses * Fix dangling items with stale scores in localized sets * Various fixes and improvements - Change approve_all/reject_all to approve_accounts/reject_accounts - Change Trends::Query methods to not mutate the original query - Change Trends::Query#skip to offset - Change follow recommendations to be refreshed in a transaction * Add tests for trending statuses filtering behaviour * Fix not applying filtering scope in controller
46 lines
796 B
Ruby
46 lines
796 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Trends::StatusFilter
|
|
KEYS = %i(
|
|
trending
|
|
locale
|
|
).freeze
|
|
|
|
attr_reader :params
|
|
|
|
def initialize(params)
|
|
@params = params
|
|
end
|
|
|
|
def results
|
|
scope = Status.unscoped.kept
|
|
|
|
params.each do |key, value|
|
|
next if %w(page locale).include?(key.to_s)
|
|
|
|
scope.merge!(scope_for(key, value.to_s.strip)) if value.present?
|
|
end
|
|
|
|
scope
|
|
end
|
|
|
|
private
|
|
|
|
def scope_for(key, value)
|
|
case key.to_s
|
|
when 'trending'
|
|
trending_scope(value)
|
|
else
|
|
raise "Unknown filter: #{key}"
|
|
end
|
|
end
|
|
|
|
def trending_scope(value)
|
|
scope = Trends.statuses.query
|
|
|
|
scope = scope.in_locale(@params[:locale].to_s) if @params[:locale].present?
|
|
scope = scope.allowed if value == 'allowed'
|
|
|
|
scope.to_arel
|
|
end
|
|
end
|