Merge remote-tracking branch 'catstodon/feature/emoji_reactions'
This commit is contained in:
commit
640c1d2c42
3 changed files with 11 additions and 15 deletions
|
@ -5,7 +5,7 @@ class Api::V1::Statuses::ReactionsController < Api::BaseController
|
||||||
|
|
||||||
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, only: [:create]
|
before_action :set_status
|
||||||
|
|
||||||
def create
|
def create
|
||||||
ReactService.new.call(current_account, @status, params[:id])
|
ReactService.new.call(current_account, @status, params[:id])
|
||||||
|
@ -13,15 +13,7 @@ class Api::V1::Statuses::ReactionsController < Api::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
react = current_account.status_reactions.find_by(status_id: params[:status_id], name: params[:id])
|
|
||||||
|
|
||||||
if react
|
|
||||||
@status = react.status
|
|
||||||
UnreactWorker.perform_async(current_account.id, @status.id, params[:id])
|
UnreactWorker.perform_async(current_account.id, @status.id, params[: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, reactions_map: { @status.id => false })
|
render json: @status, serializer: REST::StatusSerializer, relationships: StatusRelationshipsPresenter.new([@status], current_account.id, reactions_map: { @status.id => false })
|
||||||
rescue Mastodon::NotPermittedError
|
rescue Mastodon::NotPermittedError
|
||||||
|
|
|
@ -9,7 +9,7 @@ class StatusReactionValidator < ActiveModel::Validator
|
||||||
return if reaction.name.blank?
|
return if reaction.name.blank?
|
||||||
|
|
||||||
reaction.errors.add(:name, I18n.t('reactions.errors.unrecognized_emoji')) if reaction.custom_emoji_id.blank? && !unicode_emoji?(reaction.name)
|
reaction.errors.add(:name, I18n.t('reactions.errors.unrecognized_emoji')) if reaction.custom_emoji_id.blank? && !unicode_emoji?(reaction.name)
|
||||||
reaction.errors.add(:base, I18n.t('reactions.errors.limit_reached')) if reaction.account.local? && limit_reached?(reaction)
|
reaction.errors.add(:base, I18n.t('reactions.errors.limit_reached')) if reaction.account.local? && new_reaction?(reaction) && limit_reached?(reaction)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -18,6 +18,10 @@ class StatusReactionValidator < ActiveModel::Validator
|
||||||
SUPPORTED_EMOJIS.include?(name)
|
SUPPORTED_EMOJIS.include?(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def new_reaction?(reaction)
|
||||||
|
!reaction.status.status_reactions.exists?(status: reaction.status, account: reaction.account, name: reaction.name)
|
||||||
|
end
|
||||||
|
|
||||||
def limit_reached?(reaction)
|
def limit_reached?(reaction)
|
||||||
reaction.status.status_reactions.where(status: reaction.status, account: reaction.account).count >= LIMIT
|
reaction.status.status_reactions.where(status: reaction.status, account: reaction.account).count >= LIMIT
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
Fabricator(:status_reaction) do
|
Fabricator(:status_reaction) do
|
||||||
account nil
|
account
|
||||||
status nil
|
status
|
||||||
name 'MyString'
|
name '👍'
|
||||||
custom_emoji nil
|
custom_emoji
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue