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.

42 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. class AfterBlockDomainFromAccountService < BaseService
  3. # This service does not create an AccountDomainBlock record,
  4. # it's meant to be called after such a record has been created
  5. # synchronously, to "clean up"
  6. def call(account, domain)
  7. @account = account
  8. @domain = domain
  9. reject_existing_followers!
  10. reject_pending_follow_requests!
  11. end
  12. private
  13. def reject_existing_followers!
  14. @account.passive_relationships.where(account: Account.where(domain: @domain)).includes(:account).find_each do |follow|
  15. reject_follow!(follow)
  16. end
  17. end
  18. def reject_pending_follow_requests!
  19. FollowRequest.where(target_account: @account).where(account: Account.where(domain: @domain)).includes(:account).find_each do |follow_request|
  20. reject_follow!(follow_request)
  21. end
  22. end
  23. def reject_follow!(follow)
  24. follow.destroy
  25. return unless follow.account.activitypub?
  26. json = Oj.dump(ActivityPub::LinkedDataSignature.new(ActiveModelSerializers::SerializableResource.new(
  27. follow,
  28. serializer: ActivityPub::RejectFollowSerializer,
  29. adapter: ActivityPub::Adapter
  30. ).as_json).sign!(@account))
  31. ActivityPub::DeliveryWorker.perform_async(json, @account.id, follow.account.inbox_url)
  32. end
  33. end