2019-07-02 08:10:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Api::V1::Statuses::ReblogsController < Api::BaseController
|
|
|
|
include Authorization
|
|
|
|
|
|
|
|
before_action -> { doorkeeper_authorize! :write, :'write:statuses' }
|
|
|
|
before_action :require_user!
|
|
|
|
|
|
|
|
def create
|
2020-11-25 21:22:37 +00:00
|
|
|
@relog = status_for_reblog
|
|
|
|
ReblogService.new.call(current_user.account, @relog, reblog_params)
|
|
|
|
render json: @relog, serializer: REST::StatusStatSerializer
|
2019-07-02 08:10:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2020-11-25 21:22:37 +00:00
|
|
|
@my_relog = status_for_destroy
|
|
|
|
@original_status = @my_relog.reblog
|
|
|
|
|
|
|
|
authorize @my_relog, :unreblog?
|
|
|
|
|
|
|
|
RemovalWorker.perform_async(@my_relog.id)
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-11-25 21:22:37 +00:00
|
|
|
@reblogs_map = { @original_status.id => false }
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-11-25 21:22:37 +00:00
|
|
|
render json: @original_status,
|
|
|
|
serializer: REST::StatusStatSerializer,
|
|
|
|
unreblog: true,
|
|
|
|
relationships: StatusRelationshipsPresenter.new([@original_status], current_user&.account_id, reblogs_map: @reblogs_map)
|
2019-07-02 08:10:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def status_for_reblog
|
|
|
|
Status.find params[:status_id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def status_for_destroy
|
|
|
|
current_user.account.statuses.where(reblog_of_id: params[:status_id]).first!
|
|
|
|
end
|
|
|
|
|
|
|
|
def reblog_params
|
|
|
|
params.permit(:visibility, :status)
|
|
|
|
end
|
|
|
|
end
|