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.

40 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. class RejectFollowService < BaseService
  3. def call(source_account, target_account)
  4. follow_request = FollowRequest.find_by!(account: source_account, target_account: target_account)
  5. follow_request.reject!
  6. NotificationWorker.perform_async(build_xml(follow_request), target_account.id, source_account.id) unless source_account.local?
  7. end
  8. private
  9. def build_xml(follow_request)
  10. Nokogiri::XML::Builder.new do |xml|
  11. entry(xml, true) do
  12. unique_id xml, Time.now.utc, follow_request.id, 'FollowRequest'
  13. title xml, "#{follow_request.target_account.acct} rejects follow request by #{follow_request.account.acct}"
  14. author(xml) do
  15. include_author xml, follow_request.target_account
  16. end
  17. object_type xml, :activity
  18. verb xml, :reject
  19. target(xml) do
  20. author(xml) do
  21. include_author xml, follow_request.account
  22. end
  23. object_type xml, :activity
  24. verb xml, :request_friend
  25. target(xml) do
  26. include_author xml, follow_request.target_account
  27. end
  28. end
  29. end
  30. end.to_xml
  31. end
  32. end