fedibird-fe/app/validators/emoji_reaction_validator.rb

20 lines
540 B
Ruby
Raw Normal View History

2021-05-19 05:58:27 +00:00
# frozen_string_literal: true
class EmojiReactionValidator < ActiveModel::Validator
SUPPORTED_EMOJIS = Oj.load(File.read(Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_map.json'))).keys.freeze
2021-08-30 15:46:25 +00:00
LIMIT = 20
2021-05-19 05:58:27 +00:00
def validate(reaction)
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)
end
private
def unicode_emoji?(name)
SUPPORTED_EMOJIS.include?(name)
end
end