2017-06-10 09:39:26 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-11-13 15:53:22 +01:00
|
|
|
class Api::V1::Statuses::ReblogsController < Api::V1::Statuses::BaseController
|
2023-05-17 00:09:21 +02:00
|
|
|
include Redisable
|
|
|
|
include Lockable
|
2017-06-10 09:39:26 +02:00
|
|
|
|
2018-07-05 18:31:35 +02:00
|
|
|
before_action -> { doorkeeper_authorize! :write, :'write:statuses' }
|
2017-06-10 09:39:26 +02:00
|
|
|
before_action :require_user!
|
2020-07-15 14:43:19 +02:00
|
|
|
before_action :set_reblog, only: [:create]
|
2023-11-13 15:53:22 +01:00
|
|
|
skip_before_action :set_status
|
2017-06-10 09:39:26 +02:00
|
|
|
|
2020-03-08 15:17:39 +01:00
|
|
|
override_rate_limit_headers :create, family: :statuses
|
|
|
|
|
2017-06-10 09:39:26 +02:00
|
|
|
def create
|
2023-05-17 00:09:21 +02:00
|
|
|
with_redis_lock("reblog:#{current_account.id}:#{@reblog.id}") do
|
|
|
|
@status = ReblogService.new.call(current_account, @reblog, reblog_params)
|
|
|
|
end
|
2020-03-08 15:17:39 +01:00
|
|
|
|
2017-07-07 04:02:06 +02:00
|
|
|
render json: @status, serializer: REST::StatusSerializer
|
2017-06-10 09:39:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2020-07-15 14:43:19 +02:00
|
|
|
@status = current_account.statuses.find_by(reblog_of_id: params[:status_id])
|
2017-06-10 09:39:26 +02:00
|
|
|
|
2020-02-27 12:32:54 +01:00
|
|
|
if @status
|
|
|
|
authorize @status, :unreblog?
|
2023-07-19 09:02:30 +02:00
|
|
|
@reblog = @status.reblog
|
|
|
|
count = [@reblog.reblogs_count - 1, 0].max
|
2020-02-27 12:32:54 +01:00
|
|
|
@status.discard
|
|
|
|
RemovalWorker.perform_async(@status.id)
|
2020-07-15 14:43:19 +02:00
|
|
|
else
|
|
|
|
@reblog = Status.find(params[:status_id])
|
2023-07-19 09:02:30 +02:00
|
|
|
count = @reblog.reblogs_count
|
2020-07-15 14:43:19 +02:00
|
|
|
authorize @reblog, :show?
|
2020-02-27 12:32:54 +01:00
|
|
|
end
|
2017-06-10 09:39:26 +02:00
|
|
|
|
2023-07-19 09:02:30 +02:00
|
|
|
relationships = StatusRelationshipsPresenter.new([@status], current_account.id, reblogs_map: { @reblog.id => false }, attributes_map: { @reblog.id => { reblogs_count: count } })
|
|
|
|
render json: @reblog, serializer: REST::StatusSerializer, relationships: relationships
|
2020-07-15 14:43:19 +02:00
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
not_found
|
2017-06-10 09:39:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-02-27 12:32:54 +01:00
|
|
|
def set_reblog
|
|
|
|
@reblog = Status.find(params[:status_id])
|
|
|
|
authorize @reblog, :show?
|
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
not_found
|
2017-06-10 09:39:26 +02:00
|
|
|
end
|
2019-03-15 04:36:41 +01:00
|
|
|
|
|
|
|
def reblog_params
|
|
|
|
params.permit(:visibility)
|
|
|
|
end
|
2017-06-10 09:39:26 +02:00
|
|
|
end
|