fedibird-fe/app/workers/refollow_worker.rb

30 lines
970 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class RefollowWorker
include Sidekiq::Worker
sidekiq_options queue: 'pull', retry: false
def perform(target_account_id)
target_account = Account.find(target_account_id)
return unless target_account.activitypub?
target_account.passive_relationships.where(account: Account.where(domain: nil)).includes(:account).reorder(nil).find_each do |follow|
2020-03-05 13:26:30 +00:00
reblogs = follow.show_reblogs?
notify = follow.notify?
delivery = follow.delivery?
# Locally unfollow remote account
follower = follow.account
follower.unfollow!(target_account)
# Schedule re-follow
begin
2020-03-05 13:26:30 +00:00
FollowService.new.call(follower, target_account, reblogs: reblogs, notify: notify, delivery: delivery, bypass_limit: true)
rescue Mastodon::NotPermittedError, ActiveRecord::RecordNotFound, Mastodon::UnexpectedResponseError, HTTP::Error, OpenSSL::SSL::SSLError
next
end
end
end
end