forked from mirrors/catstodon
Compare commits
2 commits
537bd898a0
...
1953917c19
Author | SHA1 | Date | |
---|---|---|---|
1953917c19 | |||
d99758ba9a |
5 changed files with 13 additions and 15 deletions
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue