]> cat aescling's git repositories - mastodon.git/blob - app/controllers/following_accounts_controller.rb
Use OrderedCollectionPage to return followers/following list (#4949)
[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 @follows = Follow.where(account: @account).recent.page(params[:page]).per(FOLLOW_PER_PAGE).preload(:target_account)
8
9 respond_to do |format|
10 format.html
11
12 format.json do
13 render json: collection_presenter, serializer: ActivityPub::CollectionSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json'
14 end
15 end
16 end
17
18 private
19
20 def page_url(page)
21 account_following_index_url(@account, page: page) unless page.nil?
22 end
23
24 def collection_presenter
25 page = ActivityPub::CollectionPresenter.new(
26 id: account_following_index_url(@account, page: params.fetch(:page, 1)),
27 type: :ordered,
28 size: @account.following_count,
29 items: @follows.map { |f| ActivityPub::TagManager.instance.uri_for(f.target_account) },
30 part_of: account_following_index_url(@account),
31 next: page_url(@follows.next_page),
32 prev: page_url(@follows.prev_page)
33 )
34 if params[:page].present?
35 page
36 else
37 ActivityPub::CollectionPresenter.new(
38 id: account_following_index_url(@account),
39 type: :ordered,
40 size: @account.following_count,
41 first: page
42 )
43 end
44 end
45 end
This page took 0.101512 seconds and 6 git commands to generate.