fix reaction deletion bug and clean up controller

Turns out the strange error where it would delete
the wrong reaction occurred because I forgot to
pass the emoji name to the query, which resulted
in the database deleting the first reaction it
found.  Also, this removes the unused set_reaction
callback and includes the Authorization module for
the status reactions controller.
This commit is contained in:
fef 2022-12-01 01:41:47 +00:00 committed by Jeremy Kescher
parent f1c26962f0
commit 5d94cbfc31
No known key found for this signature in database
GPG key ID: 80A419A7A613DFA4
2 changed files with 5 additions and 9 deletions

View file

@ -1,11 +1,11 @@
# frozen_string_literal: true
class Api::V1::Statuses::ReactionsController < Api::BaseController
include Authorization
before_action -> { doorkeeper_authorize! :write, :'write:favourites' }
before_action :require_user!
before_action :set_status
before_action :set_reaction, except: :update
def update
ReactService.new.call(current_account, @status, params[:id])
@ -13,16 +13,12 @@ class Api::V1::Statuses::ReactionsController < Api::BaseController
end
def destroy
UnreactService.new.call(current_account, @status)
UnreactService.new.call(current_account, @status, params[:id])
render_empty
end
private
def set_reaction
@reaction = @status.status_reactions.where(account: current_account).find_by!(name: params[:id])
end
def set_status
@status = Status.find(params[:status_id])
end

View file

@ -3,8 +3,8 @@
class UnreactService < BaseService
include Payloadable
def call(account, status)
reaction = StatusReaction.find_by(account: account, status: status)
def call(account, status, name)
reaction = StatusReaction.find_by(account: account, status: status, name: name)
return if reaction.nil?
reaction.destroy!