authorize_follow_service.rb 996 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # frozen_string_literal: true
  2. class AuthorizeFollowService < BaseService
  3. def call(source_account, target_account)
  4. follow_request = FollowRequest.find_by!(account: source_account, target_account: target_account)
  5. follow_request.authorize!
  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. author(xml) do
  13. include_author xml, follow_request.target_account
  14. end
  15. object_type xml, :activity
  16. verb xml, :authorize
  17. target(xml) do
  18. author(xml) do
  19. include_author xml, follow_request.account
  20. end
  21. object_type xml, :activity
  22. verb xml, :request_friend
  23. target(xml) do
  24. include_author xml, follow_request.target_account
  25. end
  26. end
  27. end
  28. end.to_xml
  29. end
  30. end