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.

52 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_profile
  7. purge_content
  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_in_batches do |statuses|
  16. BatchedRemoveStatusService.new.call(statuses)
  17. end
  18. [
  19. @account.media_attachments,
  20. @account.stream_entries,
  21. @account.notifications,
  22. @account.favourites,
  23. @account.active_relationships,
  24. @account.passive_relationships,
  25. ].each do |association|
  26. destroy_all(association)
  27. end
  28. end
  29. def purge_profile
  30. @account.suspended = true
  31. @account.display_name = ''
  32. @account.note = ''
  33. @account.avatar.destroy
  34. @account.header.destroy
  35. @account.save!
  36. end
  37. def unsubscribe_push_subscribers
  38. destroy_all(@account.subscriptions)
  39. end
  40. def destroy_all(association)
  41. association.in_batches.destroy_all
  42. end
  43. end