inboxes_controller.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # frozen_string_literal: true
  2. class ActivityPub::InboxesController < ActivityPub::BaseController
  3. include SignatureVerification
  4. include JsonLdHelper
  5. include AccountOwnedConcern
  6. before_action :skip_unknown_actor_delete
  7. before_action :require_signature!
  8. skip_before_action :authenticate_user!
  9. def create
  10. upgrade_account
  11. process_payload
  12. head 202
  13. end
  14. private
  15. def skip_unknown_actor_delete
  16. head 202 if unknown_deleted_account?
  17. end
  18. def unknown_deleted_account?
  19. json = Oj.load(body, mode: :strict)
  20. json.is_a?(Hash) && json['type'] == 'Delete' && json['actor'].present? && json['actor'] == value_or_id(json['object']) && !Account.where(uri: json['actor']).exists?
  21. rescue Oj::ParseError
  22. false
  23. end
  24. def account_required?
  25. params[:account_username].present?
  26. end
  27. def body
  28. return @body if defined?(@body)
  29. @body = request.body.read
  30. @body.force_encoding('UTF-8') if @body.present?
  31. request.body.rewind if request.body.respond_to?(:rewind)
  32. @body
  33. end
  34. def upgrade_account
  35. if signed_request_account.ostatus?
  36. signed_request_account.update(last_webfingered_at: nil)
  37. ResolveAccountWorker.perform_async(signed_request_account.acct)
  38. end
  39. DeliveryFailureTracker.reset!(signed_request_account.inbox_url)
  40. end
  41. def process_payload
  42. ActivityPub::ProcessingWorker.perform_async(signed_request_account.id, body, @account&.id)
  43. end
  44. end