The code powering m.abunchtell.com https://m.abunchtell.com
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

58 líneas
1.1 KiB

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