about summary refs log tree commit diff
path: root/app/models/account.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-09 17:48:44 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-09 17:48:44 +0100
commitb13e7dda1f33be43d1667b754b67df71f3187a5c (patch)
tree62f451e95bb93846744f7bcdc58fcf8dc8d6d6f9 /app/models/account.rb
parent8d7fc5da6c880e356e6861b5c5bd564c242c7991 (diff)
API pagination for all collections using Link header
Diffstat (limited to 'app/models/account.rb')
-rw-r--r--app/models/account.rb50
1 files changed, 26 insertions, 24 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 92286369e..4fb0baebe 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -133,36 +133,38 @@ class Account < ApplicationRecord
     []
   end
 
-  def self.find_local!(username)
-    find_remote!(username, nil)
-  end
+  class << self
+    def find_local!(username)
+      find_remote!(username, nil)
+    end
 
-  def self.find_remote!(username, domain)
-    where(arel_table[:username].matches(username)).where(domain.nil? ? { domain: nil } : arel_table[:domain].matches(domain)).take!
-  end
+    def find_remote!(username, domain)
+      where(arel_table[:username].matches(username)).where(domain.nil? ? { domain: nil } : arel_table[:domain].matches(domain)).take!
+    end
 
-  def self.find_local(username)
-    find_local!(username)
-  rescue ActiveRecord::RecordNotFound
-    nil
-  end
+    def find_local(username)
+      find_local!(username)
+    rescue ActiveRecord::RecordNotFound
+      nil
+    end
 
-  def self.find_remote(username, domain)
-    find_remote!(username, domain)
-  rescue ActiveRecord::RecordNotFound
-    nil
-  end
+    def find_remote(username, domain)
+      find_remote!(username, domain)
+    rescue ActiveRecord::RecordNotFound
+      nil
+    end
 
-  def self.following_map(target_account_ids, account_id)
-    Follow.where(target_account_id: target_account_ids).where(account_id: account_id).map { |f| [f.target_account_id, true] }.to_h
-  end
+    def following_map(target_account_ids, account_id)
+      Follow.where(target_account_id: target_account_ids).where(account_id: account_id).map { |f| [f.target_account_id, true] }.to_h
+    end
 
-  def self.followed_by_map(target_account_ids, account_id)
-    Follow.where(account_id: target_account_ids).where(target_account_id: account_id).map { |f| [f.account_id, true] }.to_h
-  end
+    def followed_by_map(target_account_ids, account_id)
+      Follow.where(account_id: target_account_ids).where(target_account_id: account_id).map { |f| [f.account_id, true] }.to_h
+    end
 
-  def self.blocking_map(target_account_ids, account_id)
-    Block.where(target_account_id: target_account_ids).where(account_id: account_id).map { |b| [b.target_account_id, true] }.to_h
+    def blocking_map(target_account_ids, account_id)
+      Block.where(target_account_id: target_account_ids).where(account_id: account_id).map { |b| [b.target_account_id, true] }.to_h
+    end
   end
 
   before_create do