about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorEugen <eugen@zeonfederated.com>2017-04-05 03:18:42 +0200
committerGitHub <noreply@github.com>2017-04-05 03:18:42 +0200
commitbdaf31bcc91d309d667b173bfa660f74d5569474 (patch)
treec36c6c1f2bbc52e5e1d3067db2fbdb202bc1626b /app/lib
parent58bdb9b42ee90ca2723ac28c0f45af40df1c6383 (diff)
parent086a88f3bb3e09ade9d5659d60e5b0445b30dbed (diff)
Merge branch 'master' into patch-1
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/email_validator.rb17
-rw-r--r--app/lib/feed_manager.rb34
2 files changed, 32 insertions, 19 deletions
diff --git a/app/lib/email_validator.rb b/app/lib/email_validator.rb
index 856b8b1f7..06e9375f6 100644
--- a/app/lib/email_validator.rb
+++ b/app/lib/email_validator.rb
@@ -2,17 +2,30 @@
 
 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)
+    on_blacklist?(value) || not_on_whitelist?(value)
+  end
+
+  def on_blacklist?(value)
+    return false if Rails.configuration.x.email_domains_blacklist.blank?
+
     domains = Rails.configuration.x.email_domains_blacklist.gsub('.', '\.')
     regexp  = Regexp.new("@(.+\\.)?(#{domains})", true)
 
     value =~ regexp
   end
+
+  def not_on_whitelist?(value)
+    return false if Rails.configuration.x.email_domains_whitelist.blank?
+
+    domains = Rails.configuration.x.email_domains_whitelist.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 a2efcce10..2cca1cefe 100644
--- a/app/lib/feed_manager.rb
+++ b/app/lib/feed_manager.rb
@@ -11,11 +11,11 @@ class FeedManager
     "feed:#{type}:#{id}"
   end
 
-  def filter?(timeline_type, status, receiver)
+  def filter?(timeline_type, status, receiver_id)
     if timeline_type == :home
-      filter_from_home?(status, receiver)
+      filter_from_home?(status, receiver_id)
     elsif timeline_type == :mentions
-      filter_from_mentions?(status, receiver)
+      filter_from_mentions?(status, receiver_id)
     else
       false
     end
@@ -91,39 +91,39 @@ class FeedManager
     Redis.current
   end
 
-  def filter_from_home?(status, receiver)
+  def filter_from_home?(status, receiver_id)
     return true if status.reply? && status.in_reply_to_id.nil?
 
     check_for_mutes = [status.account_id]
     check_for_mutes.concat([status.reblog.account_id]) if status.reblog?
 
-    return true if receiver.muting?(check_for_mutes)
+    return true if Mute.where(account_id: receiver_id, target_account_id: check_for_mutes).any?
 
     check_for_blocks = status.mentions.map(&:account_id)
     check_for_blocks.concat([status.reblog.account_id]) if status.reblog?
 
-    return true if receiver.blocking?(check_for_blocks)
+    return true if Block.where(account_id: receiver_id, target_account_id: check_for_blocks).any?
 
-    if status.reply? && !status.in_reply_to_account_id.nil?                   # Filter out if it's a reply
-      should_filter   = !receiver.following?(status.in_reply_to_account)      # and I'm not following the person it's a reply to
-      should_filter &&= !(receiver.id == status.in_reply_to_account_id)       # and it's not a reply to me
-      should_filter &&= !(status.account_id == status.in_reply_to_account_id) # and it's not a self-reply
+    if status.reply? && !status.in_reply_to_account_id.nil?                                                              # Filter out if it's a reply
+      should_filter   = !Follow.where(account_id: receiver_id, target_account_id: status.in_reply_to_account_id).exists? # and I'm not following the person it's a reply to
+      should_filter &&= !(receiver_id == status.in_reply_to_account_id)                                                  # and it's not a reply to me
+      should_filter &&= !(status.account_id == status.in_reply_to_account_id)                                            # and it's not a self-reply
       return should_filter
-    elsif status.reblog?                                                      # Filter out a reblog
-      return status.reblog.account.blocking?(receiver)                        # or if the author of the reblogged status is blocking me
+    elsif status.reblog?                                                                                                 # Filter out a reblog
+      return Block.where(account_id: status.reblog.account_id, target_account_id: receiver_id).exists?                   # or if the author of the reblogged status is blocking me
     end
 
     false
   end
 
-  def filter_from_mentions?(status, receiver)
+  def filter_from_mentions?(status, receiver_id)
     check_for_blocks = [status.account_id]
-    check_for_blocks.concat(status.mentions.select('account_id').map(&:account_id))
+    check_for_blocks.concat(status.mentions.pluck(:account_id))
     check_for_blocks.concat([status.in_reply_to_account]) if status.reply? && !status.in_reply_to_account_id.nil?
 
-    should_filter   = receiver.id == status.account_id                                      # Filter if I'm mentioning myself
-    should_filter ||= receiver.blocking?(check_for_blocks)                                  # or it's from someone I blocked, in reply to someone I blocked, or mentioning someone I blocked
-    should_filter ||= (status.account.silenced? && !receiver.following?(status.account))    # of if the account is silenced and I'm not following them
+    should_filter   = receiver_id == status.account_id                                                                                   # Filter if I'm mentioning myself
+    should_filter ||= Block.where(account_id: receiver_id, target_account_id: check_for_blocks).any?                                     # or it's from someone I blocked, in reply to someone I blocked, or mentioning someone I blocked
+    should_filter ||= (status.account.silenced? && !Follow.where(account_id: receiver_id, target_account_id: status.account_id).exists?) # of if the account is silenced and I'm not following them
 
     should_filter
   end