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.

38 lines
1.1 KiB

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