diff options
author | Thibaut Girka <thib@sitedethib.com> | 2020-11-25 15:31:45 +0100 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2020-11-25 15:31:45 +0100 |
commit | e71b16ae2b5623dc664c79ffa7d96282af662c78 (patch) | |
tree | db77dc96f03d7e9b51e33b379dd1f1b9bebc0343 /app/controllers/api | |
parent | 24696458bf22c8529b49f89b2791e3e07583b7e0 (diff) | |
parent | 41b38b027396d50cac2cf995f2b5830c2cf592fa (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts: - `Gemfile.lock`: glitch-soc-only dependency textually too close to updated upstream dependencies. Updated to upsteam dependencies.
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 |