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.

39 lines
1.1 KiB

  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. unique_id xml, block.created_at, block.id, 'Block'
  17. title xml, "#{block.account.acct} no longer wishes to interact with #{block.target_account.acct}"
  18. author(xml) do
  19. include_author xml, block.account
  20. end
  21. object_type xml, :activity
  22. verb xml, :block
  23. target(xml) do
  24. include_author xml, block.target_account
  25. end
  26. end
  27. end.to_xml
  28. end
  29. end