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.

82 lines
2.2 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. SuspendAccountService.new.call(@account, reserve_username: false)
  14. end
  15. end
  16. def delete_note
  17. return if object_uri.nil?
  18. unless invalid_origin?(object_uri)
  19. RedisLock.acquire(lock_options) { |_lock| delete_later!(object_uri) }
  20. Tombstone.find_or_create_by(uri: object_uri, account: @account)
  21. end
  22. @status = Status.find_by(uri: object_uri, account: @account)
  23. @status ||= Status.find_by(uri: @object['atomUri'], account: @account) if @object.is_a?(Hash) && @object['atomUri'].present?
  24. return if @status.nil?
  25. if @status.distributable?
  26. forward_for_reply
  27. forward_for_reblogs
  28. end
  29. delete_now!
  30. end
  31. def forward_for_reblogs
  32. return if @json['signature'].blank?
  33. rebloggers_ids = @status.reblogs.includes(:account).references(:account).merge(Account.local).pluck(:account_id)
  34. inboxes = Account.where(id: ::Follow.where(target_account_id: rebloggers_ids).select(:account_id)).inboxes - [@account.preferred_inbox_url]
  35. ActivityPub::LowPriorityDeliveryWorker.push_bulk(inboxes) do |inbox_url|
  36. [payload, rebloggers_ids.first, inbox_url]
  37. end
  38. end
  39. def replied_to_status
  40. return @replied_to_status if defined?(@replied_to_status)
  41. @replied_to_status = @status.thread
  42. end
  43. def reply_to_local?
  44. !replied_to_status.nil? && replied_to_status.account.local?
  45. end
  46. def forward_for_reply
  47. return unless @json['signature'].present? && reply_to_local?
  48. inboxes = replied_to_status.account.followers.inboxes - [@account.preferred_inbox_url]
  49. ActivityPub::LowPriorityDeliveryWorker.push_bulk(inboxes) do |inbox_url|
  50. [payload, replied_to_status.account_id, inbox_url]
  51. end
  52. end
  53. def delete_now!
  54. RemoveStatusService.new.call(@status, redraft: false)
  55. end
  56. def payload
  57. @payload ||= Oj.dump(@json)
  58. end
  59. def lock_options
  60. { redis: Redis.current, key: "create:#{object_uri}" }
  61. end
  62. end