From 4cb90c6bf0df4411e4bb3b66cebef488dbec3b18 Mon Sep 17 00:00:00 2001 From: Jeremy Kescher Date: Wed, 10 May 2023 20:59:58 +0200 Subject: [PATCH] Fix invalidating status reactions when they already exist Co-authored-by: Plastikmensch --- app/validators/status_reaction_validator.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/validators/status_reaction_validator.rb b/app/validators/status_reaction_validator.rb index 8c623c823..0338bf531 100644 --- a/app/validators/status_reaction_validator.rb +++ b/app/validators/status_reaction_validator.rb @@ -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