Compare commits

...

2 commits

Author SHA1 Message Date
fef
1953917c19
change reaction api to match other interactions
Status reactions had an API similar to that of
announcement reactions, using PUT and DELETE at a
single endpoint.  I believe that for statuses, it
makes more sense to follow the convention of the
other interactions and use separate POST endpoints
for create and destroy respectively.
2022-12-01 02:24:08 +00:00
fef
d99758ba9a
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.
2022-12-01 01:41:47 +00:00
5 changed files with 13 additions and 15 deletions

View file

@ -1,28 +1,24 @@
# 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
def create
ReactService.new.call(current_account, @status, params[:id])
render_empty
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

@ -416,7 +416,7 @@ export const addReaction = (statusId, name) => (dispatch, getState) => {
dispatch(addReactionRequest(statusId, name, alreadyAdded));
}
api(getState).put(`/api/v1/statuses/${statusId}/reactions/${name}`).then(() => {
api(getState).post(`/api/v1/statuses/${statusId}/react/${name}`).then(() => {
dispatch(addReactionSuccess(statusId, name, alreadyAdded));
}).catch(err => {
if (!alreadyAdded) {
@ -450,7 +450,7 @@ export const addReactionFail = (statusId, name, error) => ({
export const removeReaction = (statusId, name) => (dispatch, getState) => {
dispatch(removeReactionRequest(statusId, name));
api(getState).delete(`/api/v1/statuses/${statusId}/reactions/${name}`).then(() => {
api(getState).post(`/api/v1/statuses/${statusId}/unreact/${name}`).then(() => {
dispatch(removeReactionSuccess(statusId, name));
}).catch(err => {
dispatch(removeReactionFail(statusId, name, err));

View file

@ -436,7 +436,7 @@ export const addReaction = (statusId, name) => (dispatch, getState) => {
dispatch(addReactionRequest(statusId, name, alreadyAdded));
}
api(getState).put(`/api/v1/statuses/${statusId}/reactions/${name}`).then(() => {
api(getState).post(`/api/v1/statuses/${statusId}/react/${name}`).then(() => {
dispatch(addReactionSuccess(statusId, name, alreadyAdded));
}).catch(err => {
if (!alreadyAdded) {
@ -470,7 +470,7 @@ export const addReactionFail = (statusId, name, error) => ({
export const removeReaction = (statusId, name) => (dispatch, getState) => {
dispatch(removeReactionRequest(statusId, name));
api(getState).delete(`/api/v1/statuses/${statusId}/reactions/${name}`).then(() => {
api(getState).post(`/api/v1/statuses/${statusId}/unreact/${name}`).then(() => {
dispatch(removeReactionSuccess(statusId, name));
}).catch(err => {
dispatch(removeReactionFail(statusId, name, err));

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!

View file

@ -442,6 +442,9 @@ Rails.application.routes.draw do
resource :favourite, only: :create
post :unfavourite, to: 'favourites#destroy'
post '/react/:id', to: 'reactions#create'
post '/unreact/:id', to: 'reactions#destroy'
resource :bookmark, only: :create
post :unbookmark, to: 'bookmarks#destroy'
@ -453,7 +456,6 @@ Rails.application.routes.draw do
resource :history, only: :show
resource :source, only: :show
resources :reactions, only: [:update, :destroy]
post :translate, to: 'translations#create'
end