]> cat aescling's git repositories - mastodon.git/commitdiff
Do not try to re-subscribe to unsubscribed accounts (#4653)
authorEugen Rochko <eugen@zeonfederated.com>
Mon, 21 Aug 2017 15:32:41 +0000 (17:32 +0200)
committerGitHub <noreply@github.com>
Mon, 21 Aug 2017 15:32:41 +0000 (17:32 +0200)
app/models/account.rb
app/services/block_domain_service.rb
app/services/subscribe_service.rb
spec/models/account_spec.rb

index c4c168160e04db8468fa0be203c55edb7ea3db4d..c3be975fb6f223a49cee615732cfee46ebd9d07a 100644 (file)
@@ -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!
index a6b3c4cdbfc4b9a0e5a7995bba40cd3aeee78a14..1473bc841fc4d799331d8efe8400f563f9909724 100644 (file)
@@ -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
index d3e41e691d2eccb5c566f5897068f262ea90b23c..5617f98f4e884b4d10c2720feb15ab1ce3ef8744 100644 (file)
@@ -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
index eeaebb7794737f95a4545727ff7203454ec86611..aef0c3082175c45e5c9643d128206de8d1288a3a 100644 (file)
@@ -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!))