about summary refs log tree commit diff
path: root/app/models/account_filter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/account_filter.rb')
-rw-r--r--app/models/account_filter.rb21
1 files changed, 12 insertions, 9 deletions
diff --git a/app/models/account_filter.rb b/app/models/account_filter.rb
index 186b38cd7..1a8cc5192 100644
--- a/app/models/account_filter.rb
+++ b/app/models/account_filter.rb
@@ -18,8 +18,6 @@ class AccountFilter
   private
 
   def scope_for(key, value)
-    accounts = Account.arel_table
-
     case key.to_s
     when 'local'
       Account.local
@@ -34,21 +32,26 @@ class AccountFilter
     when 'suspended'
       Account.suspended
     when 'username'
-      Account.where(accounts[:username].matches("#{value}%"))
+      Account.matches_username(value)
     when 'display_name'
-      Account.where(accounts[:display_name].matches("#{value}%"))
+      Account.matches_display_name(value)
     when 'email'
-      users = User.arel_table
-      Account.joins(:user).merge(User.where(users[:email].matches("#{value}%")))
+      accounts_with_users.merge User.matches_email(value)
     when 'ip'
-      return Account.default_scoped unless valid_ip?(value)
-      matches_ip = User.where(current_sign_in_ip: value).or(User.where(last_sign_in_ip: value))
-      Account.joins(:user).merge(matches_ip)
+      if valid_ip?(value)
+        accounts_with_users.merge User.with_recent_ip_address(value)
+      else
+        Account.default_scoped
+      end
     else
       raise "Unknown filter: #{key}"
     end
   end
 
+  def accounts_with_users
+    Account.joins(:user)
+  end
+
   def valid_ip?(value)
     IPAddr.new(value)
     true