refollow_worker.rb 975 B

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