about summary refs log tree commit diff
path: root/app/workers/refollow_worker.rb
blob: 66bcd27c3e40c4816c262cb763fd19c710de744e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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.protocol == :activitypub

    target_account.followers.where(domain: nil).find_each do |follower|
      # Locally unfollow remote account
      follower.unfollow!(target_account)

      # Schedule re-follow
      begin
        FollowService.new.call(follower, target_account)
      rescue Mastodon::NotPermittedError, ActiveRecord::RecordNotFound, Mastodon::UnexpectedResponseError, HTTP::Error, OpenSSL::SSL::SSLError
        next
      end
    end
  end
end