diff --git a/app/lib/activitypub/activity/announce.rb b/app/lib/activitypub/activity/announce.rb index b57dca9ad7..379235e105 100644 --- a/app/lib/activitypub/activity/announce.rb +++ b/app/lib/activitypub/activity/announce.rb @@ -26,6 +26,9 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity Trends.register!(@status) + # If we got a new reblog, the account is probably not suspended at origin anymore + @account.schedule_suspension_recheck!(interaction_time: @status.created_at) + distribute end diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 06bc940949..617f92291b 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -53,6 +53,9 @@ class ActivityPub::Activity::Create < ActivityPub::Activity process_quote process_audience + # If we got a new status, the account is probably not suspended at origin anymore + @account.schedule_suspension_recheck!(interaction_time: @params[:created_at]) + ApplicationRecord.transaction do @status = Status.create!(@params) attach_tags(@status) diff --git a/app/lib/activitypub/activity/follow.rb b/app/lib/activitypub/activity/follow.rb index 97e41ab789..5ff573aa64 100644 --- a/app/lib/activitypub/activity/follow.rb +++ b/app/lib/activitypub/activity/follow.rb @@ -8,6 +8,8 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity return if target_account.nil? || !target_account.local? || delete_arrived_first?(@json['id']) + @account.schedule_suspension_recheck! + # Update id of already-existing follow requests existing_follow_request = ::FollowRequest.find_by(account: @account, target_account: target_account) unless existing_follow_request.nil? diff --git a/app/lib/activitypub/activity/like.rb b/app/lib/activitypub/activity/like.rb index aa1dc30403..ff0f09b01f 100644 --- a/app/lib/activitypub/activity/like.rb +++ b/app/lib/activitypub/activity/like.rb @@ -6,6 +6,8 @@ class ActivityPub::Activity::Like < ActivityPub::Activity return if original_status.nil? || !original_status.account.local? || delete_arrived_first?(@json['id']) || @account.favourited?(original_status) + @account.schedule_suspension_recheck! + favourite = original_status.favourites.create!(account: @account) LocalNotificationWorker.perform_async(original_status.account_id, favourite.id, 'Favourite', 'favourite') diff --git a/app/models/account.rb b/app/models/account.rb index 53bf2407e8..b8ede37c16 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -64,6 +64,7 @@ class Account < ApplicationRecord trust_level ) + SUSPENSION_REFRESH_INTERVAL = 1.day.freeze BACKGROUND_REFRESH_INTERVAL = 1.week.freeze REFRESH_DEADLINE = 6.hours STALE_THRESHOLD = 1.day @@ -250,6 +251,14 @@ class Account < ApplicationRecord AccountRefreshWorker.perform_in(rand(REFRESH_DEADLINE), id) end + def schedule_suspension_recheck!(interaction_time: nil) + return unless suspended? && suspension_origin_remote? + return if last_webfingered_at.present? && last_webfingered_at >= SUSPENSION_REFRESH_INTERVAL.ago + return if interaction_time.present? && interaction_time < suspended_at + + RemoteAccountRefreshWorker.perform_async(id) + end + def refresh! ResolveAccountService.new.call(acct) unless local? end diff --git a/app/workers/remote_account_refresh_worker.rb b/app/workers/remote_account_refresh_worker.rb index 9632936b54..cc0c50f691 100644 --- a/app/workers/remote_account_refresh_worker.rb +++ b/app/workers/remote_account_refresh_worker.rb @@ -8,17 +8,11 @@ class RemoteAccountRefreshWorker sidekiq_options queue: 'pull', retry: 3 def perform(id) - account = Account.find_by(id: id) - return if account.nil? || account.local? + account = Account.remote.find_by(id: id) + return if account.nil? ActivityPub::FetchRemoteAccountService.new.call(account.uri) rescue Mastodon::UnexpectedResponseError => e - response = e.response - - if response_error_unsalvageable?(response) - # Give up - else - raise e - end + raise e unless response_error_unsalvageable?(e.response) end end