2019-11-13 22:02:10 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-11-13 14:53:22 +00:00
|
|
|
class Api::V1::Statuses::BookmarksController < Api::V1::Statuses::BaseController
|
2019-11-13 22:02:10 +00:00
|
|
|
before_action -> { doorkeeper_authorize! :write, :'write:bookmarks' }
|
|
|
|
before_action :require_user!
|
2023-11-13 14:53:22 +00:00
|
|
|
skip_before_action :set_status, only: [:destroy]
|
2019-11-13 22:02:10 +00:00
|
|
|
|
|
|
|
def create
|
2020-02-27 11:32:54 +00:00
|
|
|
current_account.bookmarks.find_or_create_by!(account: current_account, status: @status)
|
2019-11-13 22:02:10 +00:00
|
|
|
render json: @status, serializer: REST::StatusSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2020-08-19 17:02:06 +00: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 11:32:54 +00:00
|
|
|
bookmark&.destroy!
|
2019-11-13 22:02:10 +00:00
|
|
|
|
2020-02-27 11:32:54 +00:00
|
|
|
render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_account.id, bookmarks_map: { @status.id => false })
|
2020-08-19 17:02:06 +00:00
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
not_found
|
2019-11-13 22:02:10 +00:00
|
|
|
end
|
|
|
|
end
|