The code powering m.abunchtell.com https://m.abunchtell.com
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

25 行
790 B

  1. # frozen_string_literal: true
  2. class ReactionValidator < ActiveModel::Validator
  3. SUPPORTED_EMOJIS = Oj.load(File.read(Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_map.json'))).keys.freeze
  4. LIMIT = 8
  5. def validate(reaction)
  6. return if reaction.name.blank? || reaction.custom_emoji_id.present?
  7. reaction.errors.add(:name, I18n.t('reactions.errors.unrecognized_emoji')) unless unicode_emoji?(reaction.name)
  8. reaction.errors.add(:base, I18n.t('reactions.errors.limit_reached')) if limit_reached?(reaction)
  9. end
  10. private
  11. def unicode_emoji?(name)
  12. SUPPORTED_EMOJIS.include?(name)
  13. end
  14. def limit_reached?(reaction)
  15. reaction.announcement.announcement_reactions.where.not(name: reaction.name).count('distinct name') >= LIMIT
  16. end
  17. end