follow.rb 883 B

123456789101112131415161718192021222324
  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. # Fast-forward repeat follow requests
  7. if @account.following?(target_account)
  8. AuthorizeFollowService.new.call(@account, target_account, skip_follow_request: true)
  9. return
  10. end
  11. follow_request = FollowRequest.create!(account: @account, target_account: target_account)
  12. if target_account.locked?
  13. NotifyService.new.call(target_account, follow_request)
  14. else
  15. AuthorizeFollowService.new.call(@account, target_account)
  16. NotifyService.new.call(target_account, ::Follow.find_by(account: @account, target_account: target_account))
  17. end
  18. end
  19. end