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.

17 lines
745 B

  1. # frozen_string_literal: true
  2. class FamiliarFollowersPresenter
  3. class Result < ActiveModelSerializers::Model
  4. attributes :id, :accounts
  5. end
  6. def initialize(accounts, current_account_id)
  7. @accounts = accounts
  8. @current_account_id = current_account_id
  9. end
  10. def accounts
  11. map = Follow.includes(account: :account_stat).where(target_account_id: @accounts.map(&:id)).where(account_id: Follow.where(account_id: @current_account_id).joins(:target_account).merge(Account.where(hide_collections: [nil, false])).select(:target_account_id)).group_by(&:target_account_id)
  12. @accounts.map { |account| Result.new(id: account.id, accounts: (account.hide_collections? ? [] : (map[account.id] || [])).map(&:account)) }
  13. end
  14. end