diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2017-08-21 17:32:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-21 17:32:41 +0200 |
commit | 3534e115e5127f12292a84442b46ce93643c6d0d (patch) | |
tree | dbfe60842ddc837defb61a087b078cda8c207636 | |
parent | ea958cae7f6c960bdb54214c12de2083ab0e25b0 (diff) |
Do not try to re-subscribe to unsubscribed accounts (#4653)
-rw-r--r-- | app/models/account.rb | 6 | ||||
-rw-r--r-- | app/services/block_domain_service.rb | 2 | ||||
-rw-r--r-- | app/services/subscribe_service.rb | 2 | ||||
-rw-r--r-- | spec/models/account_spec.rb | 1 |
4 files changed, 5 insertions, 6 deletions
diff --git a/app/models/account.rb b/app/models/account.rb index c4c168160..c3be975fb 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -91,7 +91,7 @@ class Account < ApplicationRecord scope :local, -> { where(domain: nil) } scope :without_followers, -> { where(followers_count: 0) } scope :with_followers, -> { where('followers_count > 0') } - scope :expiring, ->(time) { where(subscription_expires_at: nil).or(where('subscription_expires_at < ?', time)).remote.with_followers } + scope :expiring, ->(time) { remote.where.not(subscription_expires_at: nil).where('subscription_expires_at < ?', time) } scope :partitioned, -> { order('row_number() over (partition by domain)') } scope :silenced, -> { where(silenced: true) } scope :suspended, -> { where(suspended: true) } @@ -134,11 +134,11 @@ class Account < ApplicationRecord end def keypair - OpenSSL::PKey::RSA.new(private_key || public_key) + @keypair ||= OpenSSL::PKey::RSA.new(private_key || public_key) end def subscription(webhook_url) - OStatus2::Subscription.new(remote_url, secret: secret, lease_seconds: 30.days.seconds, webhook: webhook_url, hub: hub_url) + @subscription ||= OStatus2::Subscription.new(remote_url, secret: secret, webhook: webhook_url, hub: hub_url) end def save_with_optional_media! diff --git a/app/services/block_domain_service.rb b/app/services/block_domain_service.rb index a6b3c4cdb..1473bc841 100644 --- a/app/services/block_domain_service.rb +++ b/app/services/block_domain_service.rb @@ -30,7 +30,7 @@ class BlockDomainService < BaseService def suspend_accounts! blocked_domain_accounts.where(suspended: false).find_each do |account| - account.subscription(api_subscription_url(account.id)).unsubscribe if account.subscribed? + UnsubscribeService.new.call(account) if account.subscribed? SuspendAccountService.new.call(account) end end diff --git a/app/services/subscribe_service.rb b/app/services/subscribe_service.rb index d3e41e691..5617f98f4 100644 --- a/app/services/subscribe_service.rb +++ b/app/services/subscribe_service.rb @@ -2,7 +2,7 @@ class SubscribeService < BaseService def call(account) - return unless account.ostatus? + return if account.hub_url.blank? @account = account @account.secret = SecureRandom.hex diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index eeaebb779..aef0c3082 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -642,7 +642,6 @@ RSpec.describe Account, type: :model do it 'returns remote accounts with followers whose subscription expiration date is past or not given' do local = Fabricate(:account, domain: nil) matches = [ - { domain: 'remote', subscription_expires_at: nil }, { domain: 'remote', subscription_expires_at: '2000-01-01T00:00:00Z' }, ].map(&method(:Fabricate).curry(2).call(:account)) matches.each(&local.method(:follow!)) |