logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

announce.rb (1186B)


  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. visibility: original_status.visibility
  15. )
  16. distribute(status)
  17. status
  18. end
  19. private
  20. def fetch_remote_original_status
  21. if object_uri.start_with?('http')
  22. return if ActivityPub::TagManager.instance.local_uri?(object_uri)
  23. ActivityPub::FetchRemoteStatusService.new.call(object_uri, id: true)
  24. elsif @object['url'].present?
  25. ::FetchRemoteStatusService.new.call(@object['url'])
  26. end
  27. end
  28. def announceable?(status)
  29. status.account_id == @account.id || status.public_visibility? || status.unlisted_visibility?
  30. end
  31. end