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.

52 lines
1.5 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::Activity::Delete < ActivityPub::Activity
  3. def perform
  4. if @account.uri == object_uri
  5. delete_person
  6. else
  7. delete_note
  8. end
  9. end
  10. private
  11. def delete_person
  12. lock_or_return("delete_in_progress:#{@account.id}") do
  13. DeleteAccountService.new.call(@account, reserve_username: false, skip_activitypub: true)
  14. end
  15. end
  16. def delete_note
  17. return if object_uri.nil?
  18. lock_or_return("delete_status_in_progress:#{object_uri}", 5.minutes.seconds) do
  19. unless invalid_origin?(object_uri)
  20. # This lock ensures a concurrent `ActivityPub::Activity::Create` either
  21. # does not create a status at all, or has finished saving it to the
  22. # database before we try to load it.
  23. # Without the lock, `delete_later!` could be called after `delete_arrived_first?`
  24. # and `Status.find` before `Status.create!`
  25. lock_or_fail("create:#{object_uri}") { delete_later!(object_uri) }
  26. Tombstone.find_or_create_by(uri: object_uri, account: @account)
  27. end
  28. @status = Status.find_by(uri: object_uri, account: @account)
  29. @status ||= Status.find_by(uri: @object['atomUri'], account: @account) if @object.is_a?(Hash) && @object['atomUri'].present?
  30. return if @status.nil?
  31. forwarder.forward! if forwarder.forwardable?
  32. delete_now!
  33. end
  34. end
  35. def forwarder
  36. @forwarder ||= ActivityPub::Forwarder.new(@account, @json, @status)
  37. end
  38. def delete_now!
  39. RemoveStatusService.new.call(@status, redraft: false)
  40. end
  41. end