]>
cat aescling's git repositories - mastodon.git/blob - app/controllers/api/v1/accounts_controller.rb
1 # frozen_string_literal: true
3 class Api
::V1::AccountsController < ApiController
4 before_action
-> { doorkeeper_authorize!
:read }, except
: [:follow, :unfollow, :block, :unblock]
5 before_action
-> { doorkeeper_authorize!
:follow }, only
: [:follow, :unfollow, :block, :unblock]
6 before_action
:require_user!
, except
: [:show, :following, :followers, :statuses]
7 before_action
:set_account, except
: [:verify_credentials, :suggestions, :search]
14 def verify_credentials
15 @account = current_user
.account
20 results
= Follow
.where(account
: @account).paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT
, params
[:max_id], params
[:since_id])
21 accounts
= Account
.where(id
: results
.map(&:target_account_id)).map
{ |a
| [a
.id
, a
] }.to_h
22 @accounts = results
.map
{ |f
| accounts
[f
.target_account_id
] }
24 set_account_counters_maps(@accounts)
26 next_path
= following_api_v1_account_url(max_id
: results
.last
.id
) if results
.size
== DEFAULT_ACCOUNTS_LIMIT
27 prev_path
= following_api_v1_account_url(since_id
: results
.first
.id
) unless results
.empty
?
29 set_pagination_headers(next_path
, prev_path
)
35 results
= Follow
.where(target_account
: @account).paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT
, params
[:max_id], params
[:since_id])
36 accounts
= Account
.where(id
: results
.map(&:account_id)).map
{ |a
| [a
.id
, a
] }.to_h
37 @accounts = results
.map
{ |f
| accounts
[f
.account_id
] }
39 set_account_counters_maps(@accounts)
41 next_path
= followers_api_v1_account_url(max_id
: results
.last
.id
) if results
.size
== DEFAULT_ACCOUNTS_LIMIT
42 prev_path
= followers_api_v1_account_url(since_id
: results
.first
.id
) unless results
.empty
?
44 set_pagination_headers(next_path
, prev_path
)
50 @accounts = @account.common_followers_with(current_user
.account
)
55 @accounts = FollowSuggestion
.get(current_user
.account_id
)
60 @statuses = @account.statuses
.with_includes
.paginate_by_max_id(DEFAULT_STATUSES_LIMIT
, params
[:max_id], params
[:since_id]).to_a
63 set_counters_maps(@statuses)
65 next_path
= statuses_api_v1_account_url(max_id
: @statuses.last
.id
) if @statuses.size
== DEFAULT_STATUSES_LIMIT
66 prev_path
= statuses_api_v1_account_url(since_id
: @statuses.first
.id
) unless @statuses.empty
?
68 set_pagination_headers(next_path
, prev_path
)
72 FollowService
.new
.call(current_user
.account
, @account.acct
)
74 render action
: :relationship
78 BlockService
.new
.call(current_user
.account
, @account)
80 render action
: :relationship
84 UnfollowService
.new
.call(current_user
.account
, @account)
86 render action
: :relationship
90 UnblockService
.new
.call(current_user
.account
, @account)
92 render action
: :relationship
96 ids
= params
[:id].is_a
?(Enumerable
) ? params
[:id].map(&:to_i) : [params
[:id].to_i
]
97 @accounts = Account
.where(id
: ids
).select('id')
98 @following = Account
.following_map(ids
, current_user
.account_id
)
99 @followed_by = Account
.followed_by_map(ids
, current_user
.account_id
)
100 @blocking = Account
.blocking_map(ids
, current_user
.account_id
)
104 limit
= params
[:limit] ? [DEFAULT_ACCOUNTS_LIMIT
, params
[:limit].to_i
].min
: DEFAULT_ACCOUNTS_LIMIT
105 @accounts = SearchService
.new
.call(params
[:q], limit
, params
[:resolve] == 'true')
107 set_account_counters_maps(@accounts)
109 render action
: :index
115 @account = Account
.find(params
[:id])
119 @following = Account
.following_map([@account.id
], current_user
.account_id
)
120 @followed_by = Account
.followed_by_map([@account.id
], current_user
.account_id
)
121 @blocking = Account
.blocking_map([@account.id
], current_user
.account_id
)
This page took 0.118809 seconds and 5 git commands to generate.