]> cat aescling's git repositories - mastodon.git/blob - app/controllers/api/v1/accounts_controller.rb
API for blocking and unblocking
[mastodon.git] / app / controllers / api / v1 / accounts_controller.rb
1 class Api::V1::AccountsController < ApiController
2 before_action :doorkeeper_authorize!
3 before_action :set_account, except: :verify_credentials
4 respond_to :json
5
6 def show
7 end
8
9 def verify_credentials
10 @account = current_user.account
11 render action: :show
12 end
13
14 def following
15 @following = @account.following
16 end
17
18 def followers
19 @followers = @account.followers
20 end
21
22 def statuses
23 @statuses = @account.statuses.with_includes.with_counters.paginate_by_max_id(20, params[:max_id], params[:since_id]).to_a
24 end
25
26 def follow
27 FollowService.new.call(current_user.account, @account.acct)
28 set_relationship
29 render action: :relationship
30 end
31
32 def block
33 BlockService.new.call(current_user.account, @account)
34 set_relationship
35 render action: :relationship
36 end
37
38 def unfollow
39 UnfollowService.new.call(current_user.account, @account)
40 set_relationship
41 render action: :relationship
42 end
43
44 def unblock
45 UnblockService.new.call(current_user.account, @account)
46 set_relationship
47 render action: :relationship
48 end
49
50 def relationships
51 ids = params[:id].is_a?(Enumerable) ? params[:id].map(&:to_i) : [params[:id].to_i]
52 @accounts = Account.find(ids)
53 @following = Account.following_map(ids, current_user.account_id)
54 @followed_by = Account.followed_by_map(ids, current_user.account_id)
55 @blocking = Account.blocking_map(ids, current_user.account_id)
56 end
57
58 private
59
60 def set_account
61 @account = Account.find(params[:id])
62 end
63
64 def set_relationship
65 @following = Account.following_map([@account.id], current_user.account_id)
66 @followed_by = Account.followed_by_map([@account.id], current_user.account_id)
67 @blocking = Account.blocking_map([@account.id], current_user.account_id)
68 end
69 end
This page took 0.096496 seconds and 5 git commands to generate.