2017-06-10 16:39:26 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Api::V1::Statuses::ReblogsController < Api::BaseController
|
|
|
|
include Authorization
|
|
|
|
|
2018-07-06 01:31:35 +09:00
|
|
|
before_action -> { doorkeeper_authorize! :write, :'write:statuses' }
|
2017-06-10 16:39:26 +09:00
|
|
|
before_action :require_user!
|
2020-02-27 20:32:54 +09:00
|
|
|
before_action :set_reblog
|
2017-06-10 16:39:26 +09:00
|
|
|
|
2020-03-08 23:17:39 +09:00
|
|
|
override_rate_limit_headers :create, family: :statuses
|
|
|
|
|
2017-06-10 16:39:26 +09:00
|
|
|
def create
|
2020-02-27 20:32:54 +09:00
|
|
|
@status = ReblogService.new.call(current_account, @reblog, reblog_params)
|
2020-03-08 23:17:39 +09:00
|
|
|
|
2017-07-07 11:02:06 +09:00
|
|
|
render json: @status, serializer: REST::StatusSerializer
|
2017-06-10 16:39:26 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2020-02-27 20:32:54 +09:00
|
|
|
@status = current_account.statuses.find_by(reblog_of_id: @reblog.id)
|
2017-06-10 16:39:26 +09:00
|
|
|
|
2020-02-27 20:32:54 +09:00
|
|
|
if @status
|
|
|
|
authorize @status, :unreblog?
|
|
|
|
@status.discard
|
|
|
|
RemovalWorker.perform_async(@status.id)
|
|
|
|
end
|
2017-06-10 16:39:26 +09:00
|
|
|
|
2020-02-27 20:32:54 +09:00
|
|
|
render json: @reblog, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_account.id, reblogs_map: { @reblog.id => false })
|
2017-06-10 16:39:26 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-02-27 20:32:54 +09:00
|
|
|
def set_reblog
|
|
|
|
@reblog = Status.find(params[:status_id])
|
|
|
|
authorize @reblog, :show?
|
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
not_found
|
2017-06-10 16:39:26 +09:00
|
|
|
end
|
2019-03-15 12:36:41 +09:00
|
|
|
|
|
|
|
def reblog_params
|
|
|
|
params.permit(:visibility)
|
|
|
|
end
|
2017-06-10 16:39:26 +09:00
|
|
|
end
|