~cytrogen/masto-fe

ref: 355e3fb5296ffd433fb484ba7e183ddd97144c78 masto-fe/app/models/account_suggestions.rb -rw-r--r-- 713 bytes
355e3fb5 — Claire Simplify `Account.by_recent_status` and `Account.by_recent_sign_in` scopes (#26840) 2 years ago
                                                                                
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
# frozen_string_literal: true

class AccountSuggestions
  SOURCES = [
    AccountSuggestions::SettingSource,
    AccountSuggestions::PastInteractionsSource,
    AccountSuggestions::GlobalSource,
  ].freeze

  def self.get(account, limit)
    SOURCES.each_with_object([]) do |source_class, suggestions|
      source_suggestions = source_class.new.get(
        account,
        skip_account_ids: suggestions.map(&:account_id),
        limit: limit - suggestions.size
      )

      suggestions.concat(source_suggestions)
    end
  end

  def self.remove(account, target_account_id)
    SOURCES.each do |source_class|
      source = source_class.new
      source.remove(account, target_account_id)
    end
  end
end