1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00
mastodon/app/workers/refollow_worker.rb
Eugen Rochko 974b1b79ce
Add option to be notified when a followed user posts (#13546)
* Add bell button

Fix #4890

* Remove duplicate type from post-deployment migration

* Fix legacy class type mappings

* Improve query performance with better index

* Fix validation

* Remove redundant index from notifications
2020-09-18 17:26:45 +02:00

28 lines
894 B
Ruby

# 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?
# 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)
rescue Mastodon::NotPermittedError, ActiveRecord::RecordNotFound, Mastodon::UnexpectedResponseError, HTTP::Error, OpenSSL::SSL::SSLError
next
end
end
end
end