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.

36 lines
1.5 KiB

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