about summary refs log tree commit diff
path: root/app/models/account.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-09-20 00:39:03 +0200
committerEugen Rochko <eugen@zeonfederated.com>2016-09-20 00:43:36 +0200
commit059ebbf48dc56971b88e26a15303a75643de8b98 (patch)
treef0d46b941f298912094fe5a87b192d6fa8d4d304 /app/models/account.rb
parent1245ee42fb9f689ffa4956f42f44a7ab75e19075 (diff)
Separate PuSH subscriptions from following, add mastodon:push:refresh task,
respect hub.lease_seconds (fix #46)
Diffstat (limited to 'app/models/account.rb')
-rw-r--r--app/models/account.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 6e96defe4..449075aa8 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -38,6 +38,12 @@ class Account < ApplicationRecord
 
   has_many :media_attachments, dependent: :destroy
 
+  scope :remote, -> { where.not(domain: nil) }
+  scope :local, -> { where(domain: nil) }
+  scope :without_followers, -> { where('(select count(f.id) from follows as f where f.target_account_id = accounts.id) = 0') }
+  scope :with_followers, -> { where('(select count(f.id) from follows as f where f.target_account_id = accounts.id) > 0') }
+  scope :expiring, -> (time) { where(subscription_expires_at: nil).or(where('subscription_expires_at < ?', time)).remote.with_followers }
+
   def follow!(other_account)
     self.active_relationships.where(target_account: other_account).first_or_create!(target_account: other_account)
   end