about summary refs log tree commit diff
path: root/app/validators
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2020-01-24 14:37:06 +0100
committerThibaut Girka <thib@sitedethib.com>2020-01-24 14:37:06 +0100
commit9adeaf2bfc1c16ca70e611b5288886b21414217b (patch)
tree53372bc9bd6f38d158aad50c768e18773b7d3f3b /app/validators
parenta8c109baca4d02cc8aed454e231518c1f8ec1844 (diff)
parent4bae4e972d43f71bffb888ac82c180b2fa3f1ada (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- `app/controllers/statuses_controller.rb`:
  Minor conflict due to theming system
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/reaction_validator.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/validators/reaction_validator.rb b/app/validators/reaction_validator.rb
new file mode 100644
index 000000000..de0f2c94b
--- /dev/null
+++ b/app/validators/reaction_validator.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class ReactionValidator < ActiveModel::Validator
+  SUPPORTED_EMOJIS = Oj.load(File.read(Rails.root.join('app', 'javascript', 'mastodon', 'features', 'emoji', 'emoji_map.json'))).keys.freeze
+
+  def validate(reaction)
+    return if reaction.name.blank? || reaction.custom_emoji_id.present?
+
+    reaction.errors.add(:name, I18n.t('reactions.errors.unrecognized_emoji')) unless unicode_emoji?(reaction.name)
+  end
+
+  private
+
+  def unicode_emoji?(name)
+    SUPPORTED_EMOJIS.include?(name)
+  end
+end