update.rb 868 B

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