refollow_worker.rb 914 B

12345678910111213141516171819202122232425262728
  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. notify = follow.notify?
  11. # Locally unfollow remote account
  12. follower = follow.account
  13. follower.unfollow!(target_account)
  14. # Schedule re-follow
  15. begin
  16. FollowService.new.call(follower, target_account, reblogs: reblogs, notify: notify, bypass_limit: true)
  17. rescue Mastodon::NotPermittedError, ActiveRecord::RecordNotFound, Mastodon::UnexpectedResponseError, HTTP::Error, OpenSSL::SSL::SSLError
  18. next
  19. end
  20. end
  21. end
  22. end