]> cat aescling's git repositories - mastodon.git/blob - app/controllers/api/v1/accounts_controller.rb
Adding sync of follow relationships to Neo4J, accounts/suggestions API
[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, :suggestions]
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 suggestions
23 @accounts = FollowSuggestion.get(current_user.account_id)
24 end
25
26 def statuses
27 @statuses = @account.statuses.with_includes.with_counters.paginate_by_max_id(20, params[:max_id], params[:since_id]).to_a
28 end
29
30 def follow
31 FollowService.new.call(current_user.account, @account.acct)
32 set_relationship
33 render action: :relationship
34 end
35
36 def block
37 BlockService.new.call(current_user.account, @account)
38 set_relationship
39 render action: :relationship
40 end
41
42 def unfollow
43 UnfollowService.new.call(current_user.account, @account)
44 set_relationship
45 render action: :relationship
46 end
47
48 def unblock
49 UnblockService.new.call(current_user.account, @account)
50 set_relationship
51 render action: :relationship
52 end
53
54 def relationships
55 ids = params[:id].is_a?(Enumerable) ? params[:id].map(&:to_i) : [params[:id].to_i]
56 @accounts = Account.find(ids)
57 @following = Account.following_map(ids, current_user.account_id)
58 @followed_by = Account.followed_by_map(ids, current_user.account_id)
59 @blocking = Account.blocking_map(ids, current_user.account_id)
60 end
61
62 private
63
64 def set_account
65 @account = Account.find(params[:id])
66 end
67
68 def set_relationship
69 @following = Account.following_map([@account.id], current_user.account_id)
70 @followed_by = Account.followed_by_map([@account.id], current_user.account_id)
71 @blocking = Account.blocking_map([@account.id], current_user.account_id)
72 end
73 end
This page took 0.133767 seconds and 4 git commands to generate.