about summary refs log tree commit diff
path: root/app/models/instance_filter.rb
blob: 9c467bc276c55d97aa7c3c27606fdefa49e9dc77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

class InstanceFilter
  KEYS = %i(
    limited
    by_domain
  ).freeze

  attr_reader :params

  def initialize(params)
    @params = params
  end

  def results
    if params[:limited].present?
      scope = DomainBlock
      scope = scope.matches_domain(params[:by_domain]) if params[:by_domain].present?
      scope.order(id: :desc)
    elsif params[:allowed].present?
      scope = DomainAllow
      scope = scope.matches_domain(params[:by_domain]) if params[:by_domain].present?
      scope.order(id: :desc)
    else
      scope = Account.remote
      scope = scope.matches_domain(params[:by_domain]) if params[:by_domain].present?
      scope.by_domain_accounts
    end
  end
end