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.

30 lines
1.0 KiB

  1. # frozen_string_literal: true
  2. class RejectFollowService < BaseService
  3. include Payloadable
  4. def call(source_account, target_account)
  5. follow_request = FollowRequest.find_by!(account: source_account, target_account: target_account)
  6. follow_request.reject!
  7. create_notification(follow_request) unless source_account.local?
  8. follow_request
  9. end
  10. private
  11. def create_notification(follow_request)
  12. if follow_request.account.ostatus?
  13. NotificationWorker.perform_async(build_xml(follow_request), follow_request.target_account_id, follow_request.account_id)
  14. elsif follow_request.account.activitypub?
  15. ActivityPub::DeliveryWorker.perform_async(build_json(follow_request), follow_request.target_account_id, follow_request.account.inbox_url)
  16. end
  17. end
  18. def build_json(follow_request)
  19. Oj.dump(serialize_payload(follow_request, ActivityPub::RejectFollowSerializer))
  20. end
  21. def build_xml(follow_request)
  22. OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request))
  23. end
  24. end