inboxes_controller.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # frozen_string_literal: true
  2. class ActivityPub::InboxesController < Api::BaseController
  3. include SignatureVerification
  4. include JsonLdHelper
  5. before_action :set_account
  6. def create
  7. if unknown_deleted_account?
  8. head 202
  9. elsif signed_request_account
  10. upgrade_account
  11. process_payload
  12. head 202
  13. else
  14. render plain: signature_verification_failure_reason, status: 401
  15. end
  16. end
  17. private
  18. def unknown_deleted_account?
  19. json = Oj.load(body, mode: :strict)
  20. 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 set_account
  25. @account = Account.find_local!(params[:account_username]) if params[:account_username]
  26. end
  27. def body
  28. return @body if defined?(@body)
  29. @body = request.body.read.force_encoding('UTF-8')
  30. request.body.rewind if request.body.respond_to?(:rewind)
  31. @body
  32. end
  33. def upgrade_account
  34. if signed_request_account.ostatus?
  35. signed_request_account.update(last_webfingered_at: nil)
  36. ResolveAccountWorker.perform_async(signed_request_account.acct)
  37. end
  38. Pubsubhubbub::UnsubscribeWorker.perform_async(signed_request_account.id) if signed_request_account.subscribed?
  39. DeliveryFailureTracker.track_inverse_success!(signed_request_account)
  40. end
  41. def process_payload
  42. ActivityPub::ProcessingWorker.perform_async(signed_request_account.id, body, @account&.id)
  43. end
  44. end