accept.rb 810 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # frozen_string_literal: true
  2. class ActivityPub::Activity::Accept < ActivityPub::Activity
  3. def perform
  4. case @object['type']
  5. when 'Follow'
  6. accept_follow
  7. end
  8. end
  9. private
  10. def accept_follow
  11. return accept_follow_for_relay if relay_follow?
  12. target_account = account_from_uri(target_uri)
  13. return if target_account.nil? || !target_account.local?
  14. follow_request = FollowRequest.find_by(account: target_account, target_account: @account)
  15. follow_request&.authorize!
  16. end
  17. def accept_follow_for_relay
  18. relay.update!(state: :accepted)
  19. end
  20. def relay
  21. @relay ||= Relay.find_by(follow_activity_id: object_uri) unless object_uri.nil?
  22. end
  23. def relay_follow?
  24. relay.present?
  25. end
  26. def target_uri
  27. @target_uri ||= value_or_id(@object['actor'])
  28. end
  29. end