refollow_worker.rb 847 B

123456789101112131415161718192021222324252627
  1. # frozen_string_literal: true
  2. class RefollowWorker
  3. include Sidekiq::Worker
  4. sidekiq_options queue: 'pull', retry: false
  5. def perform(target_account_id)
  6. target_account = Account.find(target_account_id)
  7. return unless target_account.activitypub?
  8. target_account.passive_relationships.where(account: Account.where(domain: nil)).includes(:account).reorder(nil).find_each do |follow|
  9. reblogs = follow.show_reblogs?
  10. # Locally unfollow remote account
  11. follower = follow.account
  12. follower.unfollow!(target_account)
  13. # Schedule re-follow
  14. begin
  15. FollowService.new.call(follower, target_account, reblogs: reblogs)
  16. rescue Mastodon::NotPermittedError, ActiveRecord::RecordNotFound, Mastodon::UnexpectedResponseError, HTTP::Error, OpenSSL::SSL::SSLError
  17. next
  18. end
  19. end
  20. end
  21. end