Add emoji reaction validation per account/emoji
This commit is contained in:
parent
3810837b65
commit
1efc51313d
3 changed files with 9 additions and 0 deletions
|
@ -28,6 +28,7 @@ class EmojiReaction < ApplicationRecord
|
|||
|
||||
has_one :notification, as: :activity, dependent: :destroy
|
||||
|
||||
validate :status_same_emoji_reaction
|
||||
validate :status_emoji_reactions_count
|
||||
|
||||
after_create :refresh_cache
|
||||
|
@ -53,6 +54,12 @@ class EmojiReaction < ApplicationRecord
|
|||
query
|
||||
end
|
||||
|
||||
def status_same_emoji_reaction
|
||||
if status && account && status.emoji_reactions.where(account: account).where(name: name).where(custom_emoji_id: custom_emoji_id).any?
|
||||
raise Mastodon::ValidationError, I18n.t('reactions.errors.duplication')
|
||||
end
|
||||
end
|
||||
|
||||
def status_emoji_reactions_count
|
||||
if status && account && status.emoji_reactions.where(account: account).count >= EMOJI_REACTION_PER_ACCOUNT_LIMIT
|
||||
raise Mastodon::ValidationError, I18n.t('reactions.errors.limit_reached')
|
||||
|
|
|
@ -1423,6 +1423,7 @@ en:
|
|||
title: Privacy Policy
|
||||
reactions:
|
||||
errors:
|
||||
duplication: Cannot react same things
|
||||
limit_reached: Limit of different reactions reached
|
||||
unrecognized_emoji: is not a recognized emoji
|
||||
relationships:
|
||||
|
|
|
@ -1390,6 +1390,7 @@ ja:
|
|||
title: プライバシーポリシー
|
||||
reactions:
|
||||
errors:
|
||||
duplication: 同じリアクションを複数行おうとしました
|
||||
limit_reached: リアクションの種類が上限に達しました
|
||||
unrecognized_emoji: は絵文字として認識されていません
|
||||
relationships:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue