~cytrogen/masto-fe

ref: b749de766f5a6158fd0b5f3c3201943083fc7979 masto-fe/app/presenters/familiar_followers_presenter.rb -rw-r--r-- 745 bytes
b749de76 — Michael Stanclift Migrate Dockerfile to Bookworm (#26802) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# frozen_string_literal: true

class FamiliarFollowersPresenter
  class Result < ActiveModelSerializers::Model
    attributes :id, :accounts
  end

  def initialize(accounts, current_account_id)
    @accounts           = accounts
    @current_account_id = current_account_id
  end

  def accounts
    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)
    @accounts.map { |account| Result.new(id: account.id, accounts: (account.hide_collections? ? [] : (map[account.id] || [])).map(&:account)) }
  end
end