diff options
author | Starfall <us@starfall.systems> | 2020-12-01 10:50:41 -0600 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2020-12-01 10:50:41 -0600 |
commit | 63f2eb0c84d0c51f7ece341cc3f35518a3d69520 (patch) | |
tree | 57d362f393ff7ae7fdf6b4a00d654f8dbd9c9d7c /app/controllers/api | |
parent | 19548d0a4bc303ca8017599577e21a6d522eb7bd (diff) | |
parent | 29812c2e59e02ea5ff8e4818a38b59944e2367ba (diff) |
Merge branch 'glitch' into main
Diffstat (limited to 'app/controllers/api')
-rw-r--r-- | app/controllers/api/v1/statuses/favourites_controller.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/app/controllers/api/v1/statuses/favourites_controller.rb b/app/controllers/api/v1/statuses/favourites_controller.rb index 7afa822ed..2e21ce6a0 100644 --- a/app/controllers/api/v1/statuses/favourites_controller.rb +++ b/app/controllers/api/v1/statuses/favourites_controller.rb @@ -5,7 +5,7 @@ class Api::V1::Statuses::FavouritesController < Api::BaseController before_action -> { doorkeeper_authorize! :write, :'write:favourites' } before_action :require_user! - before_action :set_status + before_action :set_status, only: [:create] def create FavouriteService.new.call(current_account, @status) @@ -13,8 +13,19 @@ class Api::V1::Statuses::FavouritesController < Api::BaseController end def destroy - UnfavouriteWorker.perform_async(current_account.id, @status.id) + fav = current_account.favourites.find_by(status_id: params[:status_id]) + + if fav + @status = fav.status + UnfavouriteWorker.perform_async(current_account.id, @status.id) + else + @status = Status.find(params[:status_id]) + authorize @status, :show? + end + render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_account.id, favourites_map: { @status.id => false }) + rescue Mastodon::NotPermittedError + not_found end private |