accept.rb 916 B

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