]> cat aescling's git repositories - mastodon.git/blob - app/controllers/following_accounts_controller.rb
Merge branch 'master' into glitch-soc/merge-upstream
[mastodon.git] / app / controllers / following_accounts_controller.rb
1 # frozen_string_literal: true
2
3 class FollowingAccountsController < ApplicationController
4 include AccountControllerConcern
5
6 def index
7 respond_to do |format|
8 format.html do
9 use_pack 'public'
10
11 next if @account.user_hides_network?
12
13 follows
14 @relationships = AccountRelationshipsPresenter.new(follows.map(&:target_account_id), current_user.account_id) if user_signed_in?
15 end
16
17 format.json do
18 raise Mastodon::NotPermittedError if params[:page].present? && @account.user_hides_network?
19
20 render json: collection_presenter,
21 serializer: ActivityPub::CollectionSerializer,
22 adapter: ActivityPub::Adapter,
23 content_type: 'application/activity+json'
24 end
25 end
26 end
27
28 private
29
30 def follows
31 @follows ||= Follow.where(account: @account).recent.page(params[:page]).per(FOLLOW_PER_PAGE).preload(:target_account)
32 end
33
34 def page_url(page)
35 account_following_index_url(@account, page: page) unless page.nil?
36 end
37
38 def collection_presenter
39 if params[:page].present?
40 ActivityPub::CollectionPresenter.new(
41 id: account_following_index_url(@account, page: params.fetch(:page, 1)),
42 type: :ordered,
43 size: @account.following_count,
44 items: follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.target_account) },
45 part_of: account_following_index_url(@account),
46 next: page_url(follows.next_page),
47 prev: page_url(follows.prev_page)
48 )
49 else
50 ActivityPub::CollectionPresenter.new(
51 id: account_following_index_url(@account),
52 type: :ordered,
53 size: @account.following_count,
54 first: page_url(1)
55 )
56 end
57 end
58 end
This page took 0.098918 seconds and 4 git commands to generate.