logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

reject_follow_service.rb (1217B)


  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. Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
  19. follow_request,
  20. serializer: ActivityPub::RejectFollowSerializer,
  21. adapter: ActivityPub::Adapter
  22. ).as_json).sign!(follow_request.target_account))
  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