2019-11-14 07:02:10 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-11-13 23:53:22 +09:00
|
|
|
class Api::V1::Statuses::BookmarksController < Api::V1::Statuses::BaseController
|
2019-11-14 07:02:10 +09:00
|
|
|
before_action -> { doorkeeper_authorize! :write, :'write:bookmarks' }
|
|
|
|
before_action :require_user!
|
2023-11-13 23:53:22 +09:00
|
|
|
skip_before_action :set_status, only: [:destroy]
|
2019-11-14 07:02:10 +09:00
|
|
|
|
|
|
|
def create
|
2020-02-27 20:32:54 +09:00
|
|
|
current_account.bookmarks.find_or_create_by!(account: current_account, status: @status)
|
2019-11-14 07:02:10 +09:00
|
|
|
render json: @status, serializer: REST::StatusSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2020-08-20 02:02:06 +09:00
|
|
|
bookmark = current_account.bookmarks.find_by(status_id: params[:status_id])
|
|
|
|
|
|
|
|
if bookmark
|
|
|
|
@status = bookmark.status
|
|
|
|
else
|
|
|
|
@status = Status.find(params[:status_id])
|
|
|
|
authorize @status, :show?
|
|
|
|
end
|
|
|
|
|
2020-02-27 20:32:54 +09:00
|
|
|
bookmark&.destroy!
|
2019-11-14 07:02:10 +09:00
|
|
|
|
2020-02-27 20:32:54 +09:00
|
|
|
render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_account.id, bookmarks_map: { @status.id => false })
|
2020-08-20 02:02:06 +09:00
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
not_found
|
2019-11-14 07:02:10 +09:00
|
|
|
end
|
|
|
|
end
|