authorize_follow_service.rb 926 B

123456789101112131415161718192021222324252627
  1. # frozen_string_literal: true
  2. class AuthorizeFollowService < BaseService
  3. include Payloadable
  4. def call(source_account, target_account, **options)
  5. if options[:skip_follow_request]
  6. follow_request = FollowRequest.new(account: source_account, target_account: target_account, uri: options[:follow_request_uri])
  7. else
  8. follow_request = FollowRequest.find_by!(account: source_account, target_account: target_account)
  9. follow_request.authorize!
  10. end
  11. create_notification(follow_request) if !source_account.local? && source_account.activitypub?
  12. follow_request
  13. end
  14. private
  15. def create_notification(follow_request)
  16. ActivityPub::DeliveryWorker.perform_async(build_json(follow_request), follow_request.target_account_id, follow_request.account.inbox_url)
  17. end
  18. def build_json(follow_request)
  19. Oj.dump(serialize_payload(follow_request, ActivityPub::AcceptFollowSerializer))
  20. end
  21. end