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.

71 lines
1.8 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. @status = Status.find_by(uri: object_uri, account: @account)
  20. @status ||= Status.find_by(uri: @object['atomUri'], account: @account) if @object.is_a?(Hash) && @object['atomUri'].present?
  21. delete_later!(object_uri)
  22. return if @status.nil?
  23. if @status.public_visibility? || @status.unlisted_visibility?
  24. forward_for_reply
  25. forward_for_reblogs
  26. end
  27. delete_now!
  28. end
  29. def forward_for_reblogs
  30. return if @json['signature'].blank?
  31. rebloggers_ids = @status.reblogs.includes(:account).references(:account).merge(Account.local).pluck(:account_id)
  32. inboxes = Account.where(id: ::Follow.where(target_account_id: rebloggers_ids).select(:account_id)).inboxes - [@account.preferred_inbox_url]
  33. ActivityPub::DeliveryWorker.push_bulk(inboxes) do |inbox_url|
  34. [payload, rebloggers_ids.first, inbox_url]
  35. end
  36. end
  37. def replied_to_status
  38. return @replied_to_status if defined?(@replied_to_status)
  39. @replied_to_status = @status.thread
  40. end
  41. def reply_to_local?
  42. !replied_to_status.nil? && replied_to_status.account.local?
  43. end
  44. def forward_for_reply
  45. return unless @json['signature'].present? && reply_to_local?
  46. ActivityPub::RawDistributionWorker.perform_async(Oj.dump(@json), replied_to_status.account_id, [@account.preferred_inbox_url])
  47. end
  48. def delete_now!
  49. RemoveStatusService.new.call(@status)
  50. end
  51. def payload
  52. @payload ||= Oj.dump(@json)
  53. end
  54. end