block_service.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # frozen_string_literal: true
  2. class BlockService < BaseService
  3. include StreamEntryRenderer
  4. def call(account, target_account)
  5. return if account.id == target_account.id
  6. UnfollowService.new.call(account, target_account) if account.following?(target_account)
  7. UnfollowService.new.call(target_account, account) if target_account.following?(account)
  8. block = account.block!(target_account)
  9. BlockWorker.perform_async(account.id, target_account.id)
  10. NotificationWorker.perform_async(build_xml(block), account.id, target_account.id) unless target_account.local?
  11. end
  12. private
  13. def build_xml(block)
  14. Nokogiri::XML::Builder.new do |xml|
  15. entry(xml, true) do
  16. title xml, "#{block.account.acct} no longer wishes to interact with #{block.target_account.acct}"
  17. author(xml) do
  18. include_author xml, block.account
  19. end
  20. object_type xml, :activity
  21. verb xml, :block
  22. target(xml) do
  23. include_author xml, block.target_account
  24. end
  25. end
  26. end.to_xml
  27. end
  28. end