update.rb 1000 B

123456789101112131415161718192021222324252627282930313233
  1. # frozen_string_literal: true
  2. class ActivityPub::Activity::Update < ActivityPub::Activity
  3. def perform
  4. dereference_object!
  5. if equals_or_includes_any?(@object['type'], %w(Application Group Organization Person Service))
  6. update_account
  7. elsif equals_or_includes_any?(@object['type'], %w(Note Question))
  8. update_status
  9. elsif converted_object_type?
  10. Status.find_by(uri: object_uri, account_id: @account.id)
  11. end
  12. end
  13. private
  14. def update_account
  15. return reject_payload! if @account.uri != object_uri
  16. ActivityPub::ProcessAccountService.new.call(@account.username, @account.domain, @object, signed_with_known_key: true, request_id: @options[:request_id])
  17. end
  18. def update_status
  19. return reject_payload! if invalid_origin?(object_uri)
  20. @status = Status.find_by(uri: object_uri, account_id: @account.id)
  21. return if @status.nil?
  22. ActivityPub::ProcessStatusUpdateService.new.call(@status, @object, request_id: @options[:request_id])
  23. end
  24. end