mastodon/app/lib/activitypub/activity/update.rb
Claire 79bf6950a5
Some checks failed
Ruby Linting / lint (push) Has been cancelled
Test one step migrations / pre_job (push) Has been cancelled
Test two step migrations / pre_job (push) Has been cancelled
Ruby Testing / build (production) (push) Has been cancelled
Ruby Testing / build (test) (push) Has been cancelled
Test one step migrations / test (14-alpine) (push) Has been cancelled
Test one step migrations / test (15-alpine) (push) Has been cancelled
Test two step migrations / test (14-alpine) (push) Has been cancelled
Test two step migrations / test (15-alpine) (push) Has been cancelled
Ruby Testing / test (1, .ruby-version) (push) Has been cancelled
Ruby Testing / test (1, 3.1) (push) Has been cancelled
Ruby Testing / test (1, 3.3) (push) Has been cancelled
Ruby Testing / test (2, .ruby-version) (push) Has been cancelled
Ruby Testing / test (2, 3.1) (push) Has been cancelled
Ruby Testing / test (2, 3.3) (push) Has been cancelled
Ruby Testing / test (3, .ruby-version) (push) Has been cancelled
Ruby Testing / test (3, 3.1) (push) Has been cancelled
Ruby Testing / test (3, 3.3) (push) Has been cancelled
Ruby Testing / test (4, .ruby-version) (push) Has been cancelled
Ruby Testing / test (4, 3.1) (push) Has been cancelled
Ruby Testing / test (4, 3.3) (push) Has been cancelled
Ruby Testing / End to End testing (.ruby-version) (push) Has been cancelled
Ruby Testing / End to End testing (3.1) (push) Has been cancelled
Ruby Testing / End to End testing (3.3) (push) Has been cancelled
Ruby Testing / Testing search (.ruby-version) (push) Has been cancelled
Ruby Testing / Testing search (3.1) (push) Has been cancelled
Ruby Testing / Testing search (3.3) (push) Has been cancelled
Fix Update importing old previously-unknown activities and treating them as recent ones (#36848)
2025-11-19 15:20:16 +01:00

51 lines
1.6 KiB
Ruby

# frozen_string_literal: true
class ActivityPub::Activity::Update < ActivityPub::Activity
# Updates to unknown objects older than that are ignored
OBJECT_AGE_THRESHOLD = 1.day
def perform
@account.schedule_refresh_if_stale!
dereference_object!
if equals_or_includes_any?(@object['type'], %w(Application Group Organization Person Service))
update_account
elsif equals_or_includes_any?(@object['type'], %w(Note Question))
update_status
elsif converted_object_type?
Status.find_by(uri: object_uri, account_id: @account.id)
end
end
private
def update_account
return reject_payload! if @account.uri != object_uri
ActivityPub::ProcessAccountService.new.call(@account.username, @account.domain, @object, signed_with_known_key: true, request_id: @options[:request_id])
end
def update_status
return reject_payload! if non_matching_uri_hosts?(@account.uri, object_uri)
@status = Status.find_by(uri: object_uri, account_id: @account.id)
# Ignore updates for old unknown objects, since those are updates we are not interested in
return if @status.nil? && object_too_old?
# We may be getting `Create` and `Update` out of order
@status ||= ActivityPub::Activity::Create.new(@json, @account, **@options).perform
return if @status.nil?
ActivityPub::ProcessStatusUpdateService.new.call(@status, @json, @object, request_id: @options[:request_id])
end
def object_too_old?
@object['published'].present? && @object['published'].to_datetime < OBJECT_AGE_THRESHOLD.ago
rescue Date::Error
false
end
end