diff options
author | Thibaut Girka <thib@sitedethib.com> | 2019-08-06 13:16:53 +0200 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2019-08-06 13:16:53 +0200 |
commit | cad2e6eb7afe96f781175cd829b70a0667d3498a (patch) | |
tree | 7efda6a7ca7dbe62d6efa42b17c1167e751c44d3 /app/validators | |
parent | 3ea7a334d89d2c4075b1dbf649d692ff49325f2e (diff) | |
parent | 1d8d553d8b5cb23cc67bd530ca9eb70a6683ab2a (diff) |
Merge branch 'master' into glitch-soc/merge-upstream
Diffstat (limited to 'app/validators')
-rw-r--r-- | app/validators/disallowed_hashtags_validator.rb | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/app/validators/disallowed_hashtags_validator.rb b/app/validators/disallowed_hashtags_validator.rb index ee06b20f6..d745b767f 100644 --- a/app/validators/disallowed_hashtags_validator.rb +++ b/app/validators/disallowed_hashtags_validator.rb @@ -4,24 +4,7 @@ class DisallowedHashtagsValidator < ActiveModel::Validator def validate(status) return unless status.local? && !status.reblog? - @status = status - tags = select_tags - - status.errors.add(:text, I18n.t('statuses.disallowed_hashtags', tags: tags.join(', '), count: tags.size)) unless tags.empty? - end - - private - - def select_tags - tags = Extractor.extract_hashtags(@status.text) - tags.keep_if { |tag| disallowed_hashtags.include? tag.downcase } - end - - def disallowed_hashtags - return @disallowed_hashtags if @disallowed_hashtags - - @disallowed_hashtags = Setting.disallowed_hashtags.nil? ? [] : Setting.disallowed_hashtags - @disallowed_hashtags = @disallowed_hashtags.split(' ') if @disallowed_hashtags.is_a? String - @disallowed_hashtags = @disallowed_hashtags.map(&:downcase) + disallowed_hashtags = Tag.matching_name(Extractor.extract_hashtags(status.text)).reject(&:usable?) + status.errors.add(:text, I18n.t('statuses.disallowed_hashtags', tags: disallowed_hashtags.map(&:name).join(', '), count: disallowed_hashtags.size)) unless disallowed_hashtags.empty? end end |