logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

send_interaction_service.rb (1041B)


  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 !target_account.ostatus? || block_notification?
  12. build_request.perform do |delivery|
  13. raise Mastodon::UnexpectedResponseError, delivery unless delivery.code > 199 && delivery.code < 300
  14. end
  15. end
  16. private
  17. def build_request
  18. request = Request.new(:post, @target_account.salmon_url, body: envelope)
  19. request.add_headers('Content-Type' => 'application/magic-envelope+xml')
  20. request
  21. end
  22. def envelope
  23. salmon.pack(@xml, @source_account.keypair)
  24. end
  25. def block_notification?
  26. DomainBlock.blocked?(@target_account.domain)
  27. end
  28. def salmon
  29. @salmon ||= OStatus2::Salmon.new
  30. end
  31. end