闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::Activity::Announce < ActivityPub::Activity
  3. def perform
  4. original_status = status_from_uri(object_uri)
  5. original_status ||= fetch_remote_original_status
  6. return if original_status.nil? || delete_arrived_first?(@json['id']) || !announceable?(original_status)
  7. status = Status.find_by(account: @account, reblog: original_status)
  8. return status unless status.nil?
  9. status = Status.create!(
  10. account: @account,
  11. reblog: original_status,
  12. uri: @json['id'],
  13. created_at: @options[:override_timestamps] ? nil : @json['published']
  14. )
  15. distribute(status)
  16. status
  17. end
  18. private
  19. def fetch_remote_original_status
  20. if object_uri.start_with?('http')
  21. return if ActivityPub::TagManager.instance.local_uri?(object_uri)
  22. ActivityPub::FetchRemoteStatusService.new.call(object_uri, id: true)
  23. elsif @object['url'].present?
  24. ::FetchRemoteStatusService.new.call(@object['url'])
  25. end
  26. end
  27. def announceable?(status)
  28. status.public_visibility? || status.unlisted_visibility?
  29. end
  30. end