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.

37 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. class UnfollowService < BaseService
  3. # Unfollow and notify the remote user
  4. # @param [Account] source_account Where to unfollow from
  5. # @param [Account] target_account Which to unfollow
  6. def call(source_account, target_account)
  7. follow = source_account.unfollow!(target_account)
  8. NotificationWorker.perform_async(build_xml(follow), source_account.id, target_account.id) unless target_account.local?
  9. UnmergeWorker.perform_async(target_account.id, source_account.id)
  10. end
  11. private
  12. def build_xml(follow)
  13. description = "#{follow.account.acct} is no longer following #{follow.target_account.acct}"
  14. Nokogiri::XML::Builder.new do |xml|
  15. entry(xml, true) do
  16. unique_id xml, Time.now.utc, follow.id, 'Follow'
  17. title xml, description
  18. content xml, description
  19. author(xml) do
  20. include_author xml, follow.account
  21. end
  22. object_type xml, :activity
  23. verb xml, :unfollow
  24. target(xml) do
  25. include_author xml, follow.target_account
  26. end
  27. end
  28. end.to_xml
  29. end
  30. end