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.

34 lines
1.5 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::Activity::Follow < ActivityPub::Activity
  3. def perform
  4. target_account = account_from_uri(object_uri)
  5. return if target_account.nil? || !target_account.local? || delete_arrived_first?(@json['id']) || @account.requested?(target_account)
  6. if target_account.blocking?(@account) || target_account.domain_blocking?(@account.domain) || target_account.moved?
  7. reject_follow_request!(target_account)
  8. return
  9. end
  10. # Fast-forward repeat follow requests
  11. if @account.following?(target_account)
  12. AuthorizeFollowService.new.call(@account, target_account, skip_follow_request: true, follow_request_uri: @json['id'])
  13. return
  14. end
  15. follow_request = FollowRequest.create!(account: @account, target_account: target_account, uri: @json['id'])
  16. if target_account.locked?
  17. NotifyService.new.call(target_account, follow_request)
  18. else
  19. AuthorizeFollowService.new.call(@account, target_account)
  20. NotifyService.new.call(target_account, ::Follow.find_by(account: @account, target_account: target_account))
  21. end
  22. end
  23. def reject_follow_request!(target_account)
  24. json = ActiveModelSerializers::SerializableResource.new(FollowRequest.new(account: @account, target_account: target_account, uri: @json['id']), serializer: ActivityPub::RejectFollowSerializer, adapter: ActivityPub::Adapter).to_json
  25. ActivityPub::DeliveryWorker.perform_async(json, target_account.id, @account.inbox_url)
  26. end
  27. end