about summary refs log tree commit diff
path: root/app/controllers/api/v1/statuses/bookmarks_controller.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-02-27 12:38:17 +0100
committerGitHub <noreply@github.com>2020-02-27 12:38:17 +0100
commite1d29f7d9f85a25af7a1595d2c9afc127ab36ca7 (patch)
tree1381461584bc328a90a2f881345e64ba990120d8 /app/controllers/api/v1/statuses/bookmarks_controller.rb
parent9ee8e1add9f937a75c2514ca88958ff02cf5573c (diff)
parent51d326f852baaa1b1c3790549e0d5941a4c13778 (diff)
Merge pull request #1290 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/controllers/api/v1/statuses/bookmarks_controller.rb')
-rw-r--r--app/controllers/api/v1/statuses/bookmarks_controller.rb27
1 files changed, 10 insertions, 17 deletions
diff --git a/app/controllers/api/v1/statuses/bookmarks_controller.rb b/app/controllers/api/v1/statuses/bookmarks_controller.rb
index bb9729cf5..a7f1eed00 100644
--- a/app/controllers/api/v1/statuses/bookmarks_controller.rb
+++ b/app/controllers/api/v1/statuses/bookmarks_controller.rb
@@ -5,35 +5,28 @@ class Api::V1::Statuses::BookmarksController < Api::BaseController
 
   before_action -> { doorkeeper_authorize! :write, :'write:bookmarks' }
   before_action :require_user!
+  before_action :set_status
 
   respond_to :json
 
   def create
-    @status = bookmarked_status
+    current_account.bookmarks.find_or_create_by!(account: current_account, status: @status)
     render json: @status, serializer: REST::StatusSerializer
   end
 
   def destroy
-    @status = requested_status
-    @bookmarks_map = { @status.id => false }
+    bookmark = current_account.bookmarks.find_by(status: @status)
+    bookmark&.destroy!
 
-    bookmark = Bookmark.find_by!(account: current_user.account, status: @status)
-    bookmark.destroy!
-
-    render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_user&.account_id, bookmarks_map: @bookmarks_map)
+    render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_account.id, bookmarks_map: { @status.id => false })
   end
 
   private
 
-  def bookmarked_status
-    authorize_with current_user.account, requested_status, :show?
-
-    bookmark = Bookmark.find_or_create_by!(account: current_user.account, status: requested_status)
-
-    bookmark.status.reload
-  end
-
-  def requested_status
-    Status.find(params[:status_id])
+  def set_status
+    @status = Status.find(params[:status_id])
+    authorize @status, :show?
+  rescue Mastodon::NotPermittedError
+    not_found
   end
 end