]> cat aescling's git repositories - mastodon.git/blob - app/controllers/api/v1/statuses_controller.rb
Move timelines API from statuses to its own controller, add a check for
[mastodon.git] / app / controllers / api / v1 / statuses_controller.rb
1 class Api::V1::StatusesController < ApiController
2 before_action -> { doorkeeper_authorize! :read }, except: [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
3 before_action -> { doorkeeper_authorize! :write }, only: [:create, :destroy, :reblog, :unreblog, :favourite, :unfavourite]
4 before_action :require_user!, except: [:show, :context, :reblogged_by, :favourited_by]
5 before_action :set_status, only: [:show, :context, :reblogged_by, :favourited_by]
6
7 respond_to :json
8
9 def show
10 end
11
12 def context
13 @context = OpenStruct.new({ ancestors: @status.ancestors, descendants: @status.descendants })
14 set_maps([@status] + @context[:ancestors] + @context[:descendants])
15 end
16
17 def reblogged_by
18 @accounts = @status.reblogged_by(40)
19 render action: :accounts
20 end
21
22 def favourited_by
23 @accounts = @status.favourited_by(40)
24 render action: :accounts
25 end
26
27 def create
28 @status = PostStatusService.new.call(current_user.account, params[:status], params[:in_reply_to_id].blank? ? nil : Status.find(params[:in_reply_to_id]), params[:media_ids])
29 render action: :show
30 end
31
32 def destroy
33 @status = Status.where(account_id: current_user.account).find(params[:id])
34 RemoveStatusService.new.call(@status)
35 render_empty
36 end
37
38 def reblog
39 @status = ReblogService.new.call(current_user.account, Status.find(params[:id])).reload
40 render action: :show
41 end
42
43 def unreblog
44 RemoveStatusService.new.call(Status.where(account_id: current_user.account, reblog_of_id: params[:id]).first!)
45 @status = Status.find(params[:id])
46 render action: :show
47 end
48
49 def favourite
50 @status = FavouriteService.new.call(current_user.account, Status.find(params[:id])).status.reload
51 render action: :show
52 end
53
54 def unfavourite
55 @status = UnfavouriteService.new.call(current_user.account, Status.find(params[:id])).status.reload
56 render action: :show
57 end
58
59 private
60
61 def set_status
62 @status = Status.find(params[:id])
63 end
64 end
This page took 0.082395 seconds and 4 git commands to generate.