reject.rb 1.1 KB

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