logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

delete.rb (1770B)


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