mirror of
https://github.com/mastodon/mastodon.git
synced 2024-10-21 00:56:14 +00:00
6e50134a42
* Add trending links * Add overriding specific links trendability * Add link type to preview cards and only trend articles Change trends review notifications from being sent every 5 minutes to being sent every 2 hours Change threshold from 5 unique accounts to 15 unique accounts * Fix tests
54 lines
1,010 B
Ruby
54 lines
1,010 B
Ruby
# frozen_string_literal: true
|
|
|
|
class PreviewCardFilter
|
|
KEYS = %i(
|
|
trending
|
|
).freeze
|
|
|
|
attr_reader :params
|
|
|
|
def initialize(params)
|
|
@params = params
|
|
end
|
|
|
|
def results
|
|
scope = PreviewCard.unscoped
|
|
|
|
params.each do |key, value|
|
|
next if key.to_s == 'page'
|
|
|
|
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)
|
|
ids = begin
|
|
case value.to_s
|
|
when 'allowed'
|
|
Trends.links.currently_trending_ids(true, -1)
|
|
else
|
|
Trends.links.currently_trending_ids(false, -1)
|
|
end
|
|
end
|
|
|
|
if ids.empty?
|
|
PreviewCard.none
|
|
else
|
|
PreviewCard.joins("join unnest(array[#{ids.map(&:to_i).join(',')}]::integer[]) with ordinality as x (id, ordering) on preview_cards.id = x.id").order('x.ordering')
|
|
end
|
|
end
|
|
end
|