闭社主体 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.

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