You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
855 B

  1. # frozen_string_literal: true
  2. class SendInteractionService < BaseService
  3. # Send an Atom representation of an interaction to a remote Salmon endpoint
  4. # @param [String] Entry XML
  5. # @param [Account] source_account
  6. # @param [Account] target_account
  7. def call(xml, source_account, target_account)
  8. @xml = xml
  9. @source_account = source_account
  10. @target_account = target_account
  11. return if block_notification?
  12. envelope = salmon.pack(@xml, @source_account.keypair)
  13. delivery = salmon.post(@target_account.salmon_url, envelope)
  14. raise "Delivery failed for #{target_account.salmon_url}: HTTP #{delivery.code}" unless delivery.code > 199 && delivery.code < 300
  15. end
  16. private
  17. def block_notification?
  18. DomainBlock.blocked?(@target_account.domain)
  19. end
  20. def salmon
  21. @salmon ||= OStatus2::Salmon.new
  22. end
  23. end