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.

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