]> cat aescling's git repositories - mastodon.git/blob - app/controllers/api/v1/accounts_controller.rb
Using double splat operator (#5859)
[mastodon.git] / app / controllers / api / v1 / accounts_controller.rb
1 # frozen_string_literal: true
2
3 class Api::V1::AccountsController < Api::BaseController
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]
7 before_action :set_account
8
9 respond_to :json
10
11 def show
12 render json: @account, serializer: REST::AccountSerializer
13 end
14
15 def follow
16 FollowService.new.call(current_user.account, @account.acct, reblogs: params[:reblogs])
17
18 options = @account.locked? ? {} : { following_map: { @account.id => { reblogs: params[:reblogs] } }, requested_map: { @account.id => false } }
19
20 render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships(options)
21 end
22
23 def block
24 BlockService.new.call(current_user.account, @account)
25 render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
26 end
27
28 def mute
29 MuteService.new.call(current_user.account, @account, notifications: params[:notifications])
30 render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
31 end
32
33 def unfollow
34 UnfollowService.new.call(current_user.account, @account)
35 render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
36 end
37
38 def unblock
39 UnblockService.new.call(current_user.account, @account)
40 render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
41 end
42
43 def unmute
44 UnmuteService.new.call(current_user.account, @account)
45 render json: @account, serializer: REST::RelationshipSerializer, relationships: relationships
46 end
47
48 private
49
50 def set_account
51 @account = Account.find(params[:id])
52 end
53
54 def relationships(**options)
55 AccountRelationshipsPresenter.new([@account.id], current_user.account_id, options)
56 end
57 end
This page took 0.126822 seconds and 4 git commands to generate.