1
0

reject_follow_service.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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. create_notification(follow_request) unless source_account.local?
  7. follow_request
  8. end
  9. private
  10. def create_notification(follow_request)
  11. if follow_request.account.ostatus?
  12. NotificationWorker.perform_async(build_xml(follow_request), follow_request.target_account_id, follow_request.account_id)
  13. elsif follow_request.account.activitypub?
  14. ActivityPub::DeliveryWorker.perform_async(build_json(follow_request), follow_request.target_account_id, follow_request.account.inbox_url)
  15. end
  16. end
  17. def build_json(follow_request)
  18. ActiveModelSerializers::SerializableResource.new(
  19. follow_request,
  20. serializer: ActivityPub::RejectFollowSerializer,
  21. adapter: ActivityPub::Adapter
  22. ).to_json
  23. end
  24. def build_xml(follow_request)
  25. OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request))
  26. end
  27. end