about summary refs log tree commit diff
path: root/app/presenters
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-03-07 09:36:47 +0100
committerGitHub <noreply@github.com>2022-03-07 09:36:47 +0100
commitedf09ec747ebba5a170e27eb13663462a116ec6c (patch)
treed8e6c66a345369d21af075e6102382c846a5f248 /app/presenters
parentc439e13e1231acd763b38ea6287b60edf51cadc8 (diff)
Add `/api/v1/accounts/familiar_followers` to REST API (#17700)
* Add `/api/v1/accounts/familiar_followers` to REST API

* Change hide network preference to be stored consistently for local and remote accounts

* Add dummy classes to migration

* Apply suggestions from code review

Co-authored-by: Claire <claire.github-309c@sitedethib.com>

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
Diffstat (limited to 'app/presenters')
-rw-r--r--app/presenters/familiar_followers_presenter.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/presenters/familiar_followers_presenter.rb b/app/presenters/familiar_followers_presenter.rb
new file mode 100644
index 000000000..c1d944b80
--- /dev/null
+++ b/app/presenters/familiar_followers_presenter.rb
@@ -0,0 +1,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