logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

suspend_account_service.rb (1569B)


  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. ActivityPub::RawDistributionWorker.perform_async(delete_actor_json, @account.id) if @account.local?
  21. @account.statuses.reorder(nil).find_in_batches do |statuses|
  22. BatchedRemoveStatusService.new.call(statuses)
  23. end
  24. [
  25. @account.media_attachments,
  26. @account.stream_entries,
  27. @account.notifications,
  28. @account.favourites,
  29. @account.active_relationships,
  30. @account.passive_relationships,
  31. ].each do |association|
  32. destroy_all(association)
  33. end
  34. end
  35. def purge_profile!
  36. @account.suspended = true
  37. @account.display_name = ''
  38. @account.note = ''
  39. @account.avatar.destroy
  40. @account.header.destroy
  41. @account.save!
  42. end
  43. def unsubscribe_push_subscribers!
  44. destroy_all(@account.subscriptions)
  45. end
  46. def destroy_all(association)
  47. association.in_batches.destroy_all
  48. end
  49. def delete_actor_json
  50. payload = ActiveModelSerializers::SerializableResource.new(
  51. @account,
  52. serializer: ActivityPub::DeleteActorSerializer,
  53. adapter: ActivityPub::Adapter
  54. ).as_json
  55. Oj.dump(ActivityPub::LinkedDataSignature.new(payload).sign!(@account))
  56. end
  57. end