闭社主体 forked from https://github.com/tootsuite/mastodon
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.

45 lines
1.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. SuspendAccountService.new.call(@account)
  13. end
  14. def delete_note
  15. status = Status.find_by(uri: object_uri, account: @account)
  16. status ||= Status.find_by(uri: @object['atomUri'], account: @account) if @object.is_a?(Hash) && @object['atomUri'].present?
  17. delete_later!(object_uri)
  18. return if status.nil?
  19. forward_for_reblogs(status)
  20. delete_now!(status)
  21. end
  22. def forward_for_reblogs(status)
  23. return if @json['signature'].blank?
  24. ActivityPub::RawDistributionWorker.push_bulk(status.reblogs.includes(:account).references(:account).merge(Account.local).pluck(:account_id)) do |account_id|
  25. [payload, account_id]
  26. end
  27. end
  28. def delete_now!(status)
  29. RemoveStatusService.new.call(status)
  30. end
  31. def payload
  32. @payload ||= Oj.dump(@json)
  33. end
  34. end