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.

77 lines
2.0 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)
  14. @account.destroy!
  15. end
  16. end
  17. def delete_note
  18. return if object_uri.nil?
  19. RedisLock.acquire(lock_options) do |_lock|
  20. delete_later!(object_uri)
  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.public_visibility? || @status.unlisted_visibility?
  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::DeliveryWorker.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. ActivityPub::RawDistributionWorker.perform_async(Oj.dump(@json), replied_to_status.account_id, [@account.preferred_inbox_url])
  49. end
  50. def delete_now!
  51. RemoveStatusService.new.call(@status)
  52. end
  53. def payload
  54. @payload ||= Oj.dump(@json)
  55. end
  56. def lock_options
  57. { redis: Redis.current, key: "create:#{object_uri}" }
  58. end
  59. end