]>
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, :mute, :unmute]
5 before_action
-> { doorkeeper_authorize!
:follow }, only
: [:follow, :unfollow, :block, :unblock, :mute, :unmute]
6 before_action
:require_user!
, except
: [:show, :following, :followers, :statuses]
7 before_action
:set_account, except
: [:verify_credentials, :suggestions, :search]
13 def verify_credentials
14 @account = current_user
.account
19 results
= Follow
.where(account
: @account).paginate_by_max_id(limit_param(DEFAULT_ACCOUNTS_LIMIT
), params
[:max_id], params
[:since_id])
20 accounts
= Account
.where(id
: results
.map(&:target_account_id)).map
{ |a
| [a
.id
, a
] }.to_h
21 @accounts = results
.map
{ |f
| accounts
[f
.target_account_id
] }
23 next_path
= following_api_v1_account_url(pagination_params(max_id
: results
.last
.id
)) if results
.size
== limit_param(DEFAULT_ACCOUNTS_LIMIT
)
24 prev_path
= following_api_v1_account_url(pagination_params(since_id
: results
.first
.id
)) unless results
.empty
?
26 set_pagination_headers(next_path
, prev_path
)
32 results
= Follow
.where(target_account
: @account).paginate_by_max_id(limit_param(DEFAULT_ACCOUNTS_LIMIT
), params
[:max_id], params
[:since_id])
33 accounts
= Account
.where(id
: results
.map(&:account_id)).map
{ |a
| [a
.id
, a
] }.to_h
34 @accounts = results
.map
{ |f
| accounts
[f
.account_id
] }
36 next_path
= followers_api_v1_account_url(pagination_params(max_id
: results
.last
.id
)) if results
.size
== limit_param(DEFAULT_ACCOUNTS_LIMIT
)
37 prev_path
= followers_api_v1_account_url(pagination_params(since_id
: results
.first
.id
)) unless results
.empty
?
39 set_pagination_headers(next_path
, prev_path
)
45 @statuses = @account.statuses
.permitted_for(@account, current_account
).paginate_by_max_id(limit_param(DEFAULT_STATUSES_LIMIT
), params
[:max_id], params
[:since_id])
46 @statuses = @statuses.where(id
: MediaAttachment
.where(account
: @account).where
.not(status_id
: nil).reorder('').select('distinct status_id')) if params
[:only_media]
47 @statuses = @statuses.without_replies
if params
[:exclude_replies]
48 @statuses = cache_collection(@statuses, Status
)
52 next_path
= statuses_api_v1_account_url(statuses_pagination_params(max_id
: @statuses.last
.id
)) unless @statuses.empty
?
53 prev_path
= statuses_api_v1_account_url(statuses_pagination_params(since_id
: @statuses.first
.id
)) unless @statuses.empty
?
55 set_pagination_headers(next_path
, prev_path
)
59 FollowService
.new
.call(current_user
.account
, @account.acct
)
61 render action
: :relationship
65 BlockService
.new
.call(current_user
.account
, @account)
67 @following = { @account.id
=> false }
68 @followed_by = { @account.id
=> false }
69 @blocking = { @account.id
=> true }
70 @requested = { @account.id
=> false }
71 @muting = { @account.id
=> current_user
.account
.muting
?(@account.id
) }
73 render action
: :relationship
77 MuteService
.new
.call(current_user
.account
, @account)
79 render action
: :relationship
83 UnfollowService
.new
.call(current_user
.account
, @account)
85 render action
: :relationship
89 UnblockService
.new
.call(current_user
.account
, @account)
91 render action
: :relationship
95 UnmuteService
.new
.call(current_user
.account
, @account)
97 render action
: :relationship
101 ids
= params
[:id].is_a
?(Enumerable
) ? params
[:id].map(&:to_i) : [params
[:id].to_i
]
103 @accounts = Account
.where(id
: ids
).select('id')
104 @following = Account
.following_map(ids
, current_user
.account_id
)
105 @followed_by = Account
.followed_by_map(ids
, current_user
.account_id
)
106 @blocking = Account
.blocking_map(ids
, current_user
.account_id
)
107 @muting = Account
.muting_map(ids
, current_user
.account_id
)
108 @requested = Account
.requested_map(ids
, current_user
.account_id
)
112 @accounts = AccountSearchService
.new
.call(params
[:q], limit_param(DEFAULT_ACCOUNTS_LIMIT
), params
[:resolve] == 'true', current_account
)
114 render action
: :index
120 @account = Account
.find(params
[:id])
124 @following = Account
.following_map([@account.id
], current_user
.account_id
)
125 @followed_by = Account
.followed_by_map([@account.id
], current_user
.account_id
)
126 @blocking = Account
.blocking_map([@account.id
], current_user
.account_id
)
127 @muting = Account
.muting_map([@account.id
], current_user
.account_id
)
128 @requested = Account
.requested_map([@account.id
], current_user
.account_id
)
131 def pagination_params(core_params
)
132 params
.permit(:limit).merge(core_params
)
135 def statuses_pagination_params(core_params
)
136 params
.permit(:limit, :only_media, :exclude_replies).merge(core_params
)
This page took 0.105299 seconds and 5 git commands to generate.