From 0ab9fcb6671e0999b85db5418b3f375118340b62 Mon Sep 17 00:00:00 2001 From: noellabo Date: Mon, 20 Feb 2023 05:05:38 +0900 Subject: [PATCH] Add retry_follow_request to tootctl --- app/workers/retry_follow_request_worker.rb | 26 ++++++++++++++++++++++ lib/mastodon/accounts_cli.rb | 17 ++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 app/workers/retry_follow_request_worker.rb diff --git a/app/workers/retry_follow_request_worker.rb b/app/workers/retry_follow_request_worker.rb new file mode 100644 index 000000000..460a15586 --- /dev/null +++ b/app/workers/retry_follow_request_worker.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class RetryFollowRequestWorker + 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? + + FollowRequest.where(target_account: target_account).find_each do |follow_request| + reblogs = follow_request.show_reblogs? + notify = follow_request.notify? + delivery = follow_request.delivery? + follower = follow_request.account + + begin + UnfollowService.new.call(follower, target_account, skip_unmerge: true) + FollowService.new.call(follower, target_account, reblogs: reblogs, notify: notify, delivery: delivery, bypass_limit: true) + rescue Mastodon::NotPermittedError, ActiveRecord::RecordNotFound, Mastodon::UnexpectedResponseError, HTTP::Error, OpenSSL::SSL::SSLError + next + end + end + end +end diff --git a/lib/mastodon/accounts_cli.rb b/lib/mastodon/accounts_cli.rb index 050194801..d76797084 100644 --- a/lib/mastodon/accounts_cli.rb +++ b/lib/mastodon/accounts_cli.rb @@ -515,6 +515,23 @@ module Mastodon end end + desc 'retry_follow_request ACCT', 'Retry follow request' + long_desc <<-LONG_DESC + Retry follow request. + LONG_DESC + def retry_follow_request(acct = nil) + username, domain = acct.split('@') + target_account = Account.find_remote(username, domain) + + if target_account.nil? + say('No account(s) given', :red) + exit(1) + end + + RetryFollowRequestWorker.perform_async(target_account.id) + say('OK', :green) + end + private def rotate_keys_for_account(account, delay = 0)