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.

53 lines
1.1 KiB

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