suspend_account_service.rb 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. class SuspendAccountService < BaseService
  3. def call(account)
  4. @account = account
  5. purge_content
  6. purge_profile
  7. unsubscribe_push_subscribers
  8. end
  9. private
  10. def purge_content
  11. @account.statuses.reorder(nil).find_each do |status|
  12. # This federates out deletes to previous followers
  13. RemoveStatusService.new.call(status)
  14. end
  15. [
  16. @account.media_attachments,
  17. @account.stream_entries,
  18. @account.notifications,
  19. @account.favourites,
  20. @account.active_relationships,
  21. @account.passive_relationships
  22. ].each do |association|
  23. destroy_all(association)
  24. end
  25. end
  26. def purge_profile
  27. @account.suspended = true
  28. @account.display_name = ''
  29. @account.note = ''
  30. @account.avatar.destroy
  31. @account.header.destroy
  32. @account.save!
  33. end
  34. def unsubscribe_push_subscribers
  35. destroy_all(@account.subscriptions)
  36. end
  37. def destroy_all(association)
  38. association.in_batches.destroy_all
  39. end
  40. end