def create
if signed_request_account
+ upgrade_account
process_payload
head 201
else
@body ||= request.body.read
end
+ def upgrade_account
+ return unless signed_request_account.subscribed?
+ Pubsubhubbub::UnsubscribeWorker.perform_async(signed_request_account.id)
+ end
+
def process_payload
ActivityPub::ProcessingWorker.perform_async(signed_request_account.id, body.force_encoding('UTF-8'))
end
end
def unsubscribe
- UnsubscribeService.new.call(@account)
+ Pubsubhubbub::UnsubscribeWorker.perform_async(@account.id)
redirect_to admin_account_path(@account.id)
end
@domain = domain
@account = Account.find_by(uri: @uri)
- create_account if @account.nil?
+ create_account if @account.nil?
+ upgrade_account if @account.ostatus?
update_account
@account
def create_account
@account = Account.new
+ @account.protocol = :activitypub
@account.username = @username
@account.domain = @domain
@account.uri = @uri
@account.save!
end
+ def upgrade_account
+ ActivityPub::PostUpgradeWorker.perform_async(@account.domain)
+ end
+
def image_url(key)
value = first_of_value(@json[key])
class UnsubscribeService < BaseService
def call(account)
- return unless account.ostatus?
+ return if account.hub_url.blank?
@account = account
@response = build_request.perform
--- /dev/null
+# frozen_string_literal: true
+
+class ActivityPub::PostUpgradeWorker
+ include Sidekiq::Worker
+
+ sidekiq_options queue: 'pull'
+
+ def perform(domain)
+ Account.where(domain: domain)
+ .where(protocol: :ostatus)
+ .where.not(last_webfingered_at: nil)
+ .in_batches
+ .update_all(last_webfingered_at: nil)
+ end
+end
--- /dev/null
+# frozen_string_literal: true
+
+class Pubsubhubbub::UnsubscribeWorker
+ include Sidekiq::Worker
+
+ sidekiq_options queue: 'push', retry: false, unique: :until_executed, dead: false
+
+ def perform(account_id)
+ account = Account.find(account_id)
+ logger.debug "PuSH unsubscribing from #{account.acct}"
+ ::UnsubscribeService.new.call(account)
+ rescue ActiveRecord::RecordNotFound
+ true
+ end
+end
private
def expiring_accounts
- Account.where(protocol: :ostatus).expiring(1.day.from_now).partitioned
+ Account.expiring(1.day.from_now).partitioned
end
end
namespace :push do
desc 'Unsubscribes from PuSH updates of feeds nobody follows locally'
task clear: :environment do
- Account.remote.without_followers.where.not(subscription_expires_at: nil).find_each do |a|
- Rails.logger.debug "PuSH unsubscribing from #{a.acct}"
- UnsubscribeService.new.call(a)
- end
+ Pubsubhubbub::UnsubscribeWorker.push_bulk(Account.remote.without_followers.where.not(subscription_expires_at: nil).pluck(:id))
end
desc 'Re-subscribes to soon expiring PuSH subscriptions (deprecated)'