nyastodon/app/lib/activitypub/activity/announce.rb
Eugen Rochko 0717d9b3e6 Set snowflake IDs for backdated statuses (#5260)
- Rename Mastodon::TimestampIds into Mastodon::Snowflake for clarity
- Skip for statuses coming from inbox, aka delivered in real-time
- Skip for statuses that claim to be from the future
2017-10-08 17:34:34 +02:00

36 lines
973 B
Ruby

# frozen_string_literal: true
class ActivityPub::Activity::Announce < ActivityPub::Activity
def perform
original_status = status_from_uri(object_uri)
original_status ||= fetch_remote_original_status
return if original_status.nil? || delete_arrived_first?(@json['id'])
status = Status.find_by(account: @account, reblog: original_status)
return status unless status.nil?
status = Status.create!(
account: @account,
reblog: original_status,
uri: @json['id'],
created_at: @options[:override_timestamps] ? nil : @json['published']
)
distribute(status)
status
end
private
def fetch_remote_original_status
if object_uri.start_with?('http')
return if ActivityPub::TagManager.instance.local_uri?(object_uri)
ActivityPub::FetchRemoteStatusService.new.call(object_uri, id: true)
elsif @object['url'].present?
::FetchRemoteStatusService.new.call(@object['url'])
end
end
end