diff options
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/email_validator.rb | 18 | ||||
-rw-r--r-- | app/lib/feed_manager.rb | 9 |
2 files changed, 23 insertions, 4 deletions
diff --git a/app/lib/email_validator.rb b/app/lib/email_validator.rb new file mode 100644 index 000000000..856b8b1f7 --- /dev/null +++ b/app/lib/email_validator.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class EmailValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + return if Rails.configuration.x.email_domains_blacklist.empty? + + record.errors.add(attribute, I18n.t('users.invalid_email')) if blocked_email?(value) + end + + private + + def blocked_email?(value) + domains = Rails.configuration.x.email_domains_blacklist.gsub('.', '\.') + regexp = Regexp.new("@(.+\\.)?(#{domains})", true) + + value =~ regexp + end +end diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index b812ad1f4..e08f9a0da 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -82,12 +82,13 @@ class FeedManager end def filter_from_mentions?(status, receiver) - should_filter = receiver.id == status.account_id # Filter if I'm mentioning myself - should_filter ||= receiver.blocking?(status.account) # or it's from someone I blocked + should_filter = receiver.id == status.account_id # Filter if I'm mentioning myself + should_filter ||= receiver.blocking?(status.account) # or it's from someone I blocked should_filter ||= receiver.blocking?(status.mentions.includes(:account).map(&:account)) # or if it mentions someone I blocked + should_filter ||= (status.account.silenced? && !receiver.following?(status.account)) # of if the account is silenced and I'm not following them - if status.reply? && !status.thread.account.nil? # or it's a reply - should_filter ||= receiver.blocking?(status.thread.account) # to a user I blocked + if status.reply? && !status.thread.account.nil? # or it's a reply + should_filter ||= receiver.blocking?(status.thread.account) # to a user I blocked end should_filter |