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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Api::V1::Statuses::ReactionsController < Api::BaseController
|
class Api::V1::Statuses::ReactionsController < Api::BaseController
|
||||||
|
include Authorization
|
||||||
|
|
||||||
before_action -> { doorkeeper_authorize! :write, :'write:favourites' }
|
before_action -> { doorkeeper_authorize! :write, :'write:favourites' }
|
||||||
before_action :require_user!
|
before_action :require_user!
|
||||||
|
|
||||||
before_action :set_status
|
before_action :set_status
|
||||||
before_action :set_reaction, except: :update
|
|
||||||
|
|
||||||
def update
|
def create
|
||||||
ReactService.new.call(current_account, @status, params[:id])
|
ReactService.new.call(current_account, @status, params[:id])
|
||||||
render_empty
|
render_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
UnreactService.new.call(current_account, @status)
|
UnreactService.new.call(current_account, @status, params[:id])
|
||||||
render_empty
|
render_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_reaction
|
|
||||||
@reaction = @status.status_reactions.where(account: current_account).find_by!(name: params[:id])
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_status
|
def set_status
|
||||||
@status = Status.find(params[:status_id])
|
@status = Status.find(params[:status_id])
|
||||||
end
|
end
|
||||||
|
|
|
@ -416,7 +416,7 @@ export const addReaction = (statusId, name) => (dispatch, getState) => {
|
||||||
dispatch(addReactionRequest(statusId, name, alreadyAdded));
|
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));
|
dispatch(addReactionSuccess(statusId, name, alreadyAdded));
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
if (!alreadyAdded) {
|
if (!alreadyAdded) {
|
||||||
|
@ -450,7 +450,7 @@ export const addReactionFail = (statusId, name, error) => ({
|
||||||
export const removeReaction = (statusId, name) => (dispatch, getState) => {
|
export const removeReaction = (statusId, name) => (dispatch, getState) => {
|
||||||
dispatch(removeReactionRequest(statusId, name));
|
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));
|
dispatch(removeReactionSuccess(statusId, name));
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
dispatch(removeReactionFail(statusId, name, err));
|
dispatch(removeReactionFail(statusId, name, err));
|
||||||
|
|
|
@ -436,7 +436,7 @@ export const addReaction = (statusId, name) => (dispatch, getState) => {
|
||||||
dispatch(addReactionRequest(statusId, name, alreadyAdded));
|
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));
|
dispatch(addReactionSuccess(statusId, name, alreadyAdded));
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
if (!alreadyAdded) {
|
if (!alreadyAdded) {
|
||||||
|
@ -470,7 +470,7 @@ export const addReactionFail = (statusId, name, error) => ({
|
||||||
export const removeReaction = (statusId, name) => (dispatch, getState) => {
|
export const removeReaction = (statusId, name) => (dispatch, getState) => {
|
||||||
dispatch(removeReactionRequest(statusId, name));
|
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));
|
dispatch(removeReactionSuccess(statusId, name));
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
dispatch(removeReactionFail(statusId, name, err));
|
dispatch(removeReactionFail(statusId, name, err));
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
class UnreactService < BaseService
|
class UnreactService < BaseService
|
||||||
include Payloadable
|
include Payloadable
|
||||||
|
|
||||||
def call(account, status)
|
def call(account, status, name)
|
||||||
reaction = StatusReaction.find_by(account: account, status: status)
|
reaction = StatusReaction.find_by(account: account, status: status, name: name)
|
||||||
return if reaction.nil?
|
return if reaction.nil?
|
||||||
|
|
||||||
reaction.destroy!
|
reaction.destroy!
|
||||||
|
|
|
@ -442,6 +442,9 @@ Rails.application.routes.draw do
|
||||||
resource :favourite, only: :create
|
resource :favourite, only: :create
|
||||||
post :unfavourite, to: 'favourites#destroy'
|
post :unfavourite, to: 'favourites#destroy'
|
||||||
|
|
||||||
|
post '/react/:id', to: 'reactions#create'
|
||||||
|
post '/unreact/:id', to: 'reactions#destroy'
|
||||||
|
|
||||||
resource :bookmark, only: :create
|
resource :bookmark, only: :create
|
||||||
post :unbookmark, to: 'bookmarks#destroy'
|
post :unbookmark, to: 'bookmarks#destroy'
|
||||||
|
|
||||||
|
@ -453,7 +456,6 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
resource :history, only: :show
|
resource :history, only: :show
|
||||||
resource :source, only: :show
|
resource :source, only: :show
|
||||||
resources :reactions, only: [:update, :destroy]
|
|
||||||
|
|
||||||
post :translate, to: 'translations#create'
|
post :translate, to: 'translations#create'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue