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.

41 lines
879 B

  1. # frozen_string_literal: true
  2. class ActivityPub::Activity::Reject < ActivityPub::Activity
  3. def perform
  4. case @object['type']
  5. when 'Follow'
  6. reject_follow
  7. end
  8. end
  9. private
  10. def reject_follow
  11. return reject_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&.reject!
  16. UnfollowService.new.call(target_account, @account) if target_account.following?(@account)
  17. end
  18. def reject_follow_for_relay
  19. relay.update!(state: :rejected)
  20. end
  21. def relay
  22. @relay ||= Relay.find_by(follow_activity_id: object_uri)
  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