mirror of
https://github.com/mastodon/mastodon.git
synced 2025-11-27 10:00:50 +00:00
Fix Update importing old previously-unknown activities and treating them as recent ones (#36848)
This commit is contained in:
parent
16ee628d24
commit
8f5e95a159
|
|
@ -1,6 +1,9 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ActivityPub::Activity::Update < ActivityPub::Activity
|
class ActivityPub::Activity::Update < ActivityPub::Activity
|
||||||
|
# Updates to unknown objects older than that are ignored
|
||||||
|
OBJECT_AGE_THRESHOLD = 1.day
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
@account.schedule_refresh_if_stale!
|
@account.schedule_refresh_if_stale!
|
||||||
|
|
||||||
|
|
@ -28,6 +31,9 @@ class ActivityPub::Activity::Update < ActivityPub::Activity
|
||||||
|
|
||||||
@status = Status.find_by(uri: object_uri, account_id: @account.id)
|
@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
|
# We may be getting `Create` and `Update` out of order
|
||||||
@status ||= ActivityPub::Activity::Create.new(@json, @account, **@options).perform
|
@status ||= ActivityPub::Activity::Create.new(@json, @account, **@options).perform
|
||||||
|
|
||||||
|
|
@ -35,4 +41,10 @@ class ActivityPub::Activity::Update < ActivityPub::Activity
|
||||||
|
|
||||||
ActivityPub::ProcessStatusUpdateService.new.call(@status, @json, @object, request_id: @options[:request_id])
|
ActivityPub::ProcessStatusUpdateService.new.call(@status, @json, @object, request_id: @options[:request_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def object_too_old?
|
||||||
|
@object['published'].present? && @object['published'].to_datetime < OBJECT_AGE_THRESHOLD.ago
|
||||||
|
rescue Date::Error
|
||||||
|
false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ RSpec.describe ActivityPub::Activity do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let(:publication_date) { 1.hour.ago.utc }
|
||||||
|
|
||||||
let(:create_json) do
|
let(:create_json) do
|
||||||
{
|
{
|
||||||
'@context': [
|
'@context': [
|
||||||
|
|
@ -52,7 +54,7 @@ RSpec.describe ActivityPub::Activity do
|
||||||
'https://www.w3.org/ns/activitystreams#Public',
|
'https://www.w3.org/ns/activitystreams#Public',
|
||||||
],
|
],
|
||||||
content: 'foo',
|
content: 'foo',
|
||||||
published: '2025-05-24T11:03:10Z',
|
published: publication_date.iso8601,
|
||||||
quote: ActivityPub::TagManager.instance.uri_for(quoted_status),
|
quote: ActivityPub::TagManager.instance.uri_for(quoted_status),
|
||||||
},
|
},
|
||||||
}.deep_stringify_keys
|
}.deep_stringify_keys
|
||||||
|
|
@ -77,7 +79,7 @@ RSpec.describe ActivityPub::Activity do
|
||||||
'https://www.w3.org/ns/activitystreams#Public',
|
'https://www.w3.org/ns/activitystreams#Public',
|
||||||
],
|
],
|
||||||
content: 'foo',
|
content: 'foo',
|
||||||
published: '2025-05-24T11:03:10Z',
|
published: publication_date.iso8601,
|
||||||
quote: ActivityPub::TagManager.instance.uri_for(quoted_status),
|
quote: ActivityPub::TagManager.instance.uri_for(quoted_status),
|
||||||
quoteAuthorization: approval_uri,
|
quoteAuthorization: approval_uri,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user