闭社主体 forked from https://github.com/tootsuite/mastodon
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.4 KiB

  1. # frozen_string_literal: true
  2. class AuthorizeFollowService < BaseService
  3. def call(source_account, target_account, options = {})
  4. if options[:skip_follow_request]
  5. follow_request = FollowRequest.new(account: source_account, target_account: target_account)
  6. else
  7. follow_request = FollowRequest.find_by!(account: source_account, target_account: target_account)
  8. follow_request.authorize!
  9. end
  10. create_notification(follow_request) unless source_account.local?
  11. follow_request
  12. end
  13. private
  14. def create_notification(follow_request)
  15. if follow_request.account.ostatus?
  16. NotificationWorker.perform_async(build_xml(follow_request), follow_request.target_account_id, follow_request.account_id)
  17. elsif follow_request.account.activitypub?
  18. ActivityPub::DeliveryWorker.perform_async(build_json(follow_request), follow_request.target_account_id, follow_request.account.inbox_url)
  19. end
  20. end
  21. def build_json(follow_request)
  22. Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
  23. follow_request,
  24. serializer: ActivityPub::AcceptFollowSerializer,
  25. adapter: ActivityPub::Adapter
  26. ).as_json).sign!(follow_request.target_account))
  27. end
  28. def build_xml(follow_request)
  29. OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request))
  30. end
  31. end