about summary refs log tree commit diff
path: root/app/workers/refollow_worker.rb
blob: 4b712d3aaeb625f88beb1f53e1b1fc6af6603c81 (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
25
26
27
28
29
# 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|
      reblogs   = follow.show_reblogs?
      notify    = follow.notify?
      languages = follow.languages

      # Locally unfollow remote account
      follower = follow.account
      follower.unfollow!(target_account)

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