Fix invalidating status reactions when they already exist

Co-authored-by: Plastikmensch <plastikmensch@users.noreply.github.com>
This commit is contained in:
Jeremy Kescher 2023-05-10 20:59:58 +02:00
parent aac4edf0c5
commit 241974a74a
No known key found for this signature in database
GPG key ID: 80A419A7A613DFA4

View file

@ -9,7 +9,7 @@ class StatusReactionValidator < ActiveModel::Validator
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(: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
private
@ -18,6 +18,10 @@ class StatusReactionValidator < ActiveModel::Validator
SUPPORTED_EMOJIS.include?(name)
end
def new_reaction?(reaction)
!reaction.status.status_reactions.exists?(status: reaction.status, account: reaction.account, name: reaction.name)
end
def limit_reached?(reaction)
reaction.status.status_reactions.where(status: reaction.status, account: reaction.account).count >= LIMIT
end