diff --git a/app/services/activitypub/process_account_service.rb b/app/services/activitypub/process_account_service.rb index b54e447ad06..badb2672062 100644 --- a/app/services/activitypub/process_account_service.rb +++ b/app/services/activitypub/process_account_service.rb @@ -17,7 +17,9 @@ class ActivityPub::ProcessAccountService < BaseService create_account if @account.nil? upgrade_account if @account.ostatus? + old_public_key = @account.public_key update_account + RefollowWorker.perform_async(@account.id) if old_public_key != @account.public_key @account rescue Oj::ParseError diff --git a/app/services/resolve_remote_account_service.rb b/app/services/resolve_remote_account_service.rb index 7031c98f5ee..75360150151 100644 --- a/app/services/resolve_remote_account_service.rb +++ b/app/services/resolve_remote_account_service.rb @@ -85,8 +85,10 @@ class ResolveRemoteAccountService < BaseService def handle_ostatus create_account if @account.nil? + old_public_key = @account.public_key update_account update_account_profile if update_profile? + RefollowWorker.perform_async(@account.id) if old_public_key != @account.public_key end def update_profile? diff --git a/app/workers/refollow_worker.rb b/app/workers/refollow_worker.rb new file mode 100644 index 00000000000..9c42d427128 --- /dev/null +++ b/app/workers/refollow_worker.rb @@ -0,0 +1,23 @@ +# 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) + + 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