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.

100 lines
3.0 KiB

  1. # frozen_string_literal: true
  2. class UnsuspendAccountService < BaseService
  3. include Payloadable
  4. def call(account)
  5. @account = account
  6. unsuspend!
  7. refresh_remote_account!
  8. return if @account.nil? || @account.suspended?
  9. merge_into_home_timelines!
  10. merge_into_list_timelines!
  11. publish_media_attachments!
  12. distribute_update_actor!
  13. end
  14. private
  15. def unsuspend!
  16. @account.unsuspend! if @account.suspended?
  17. end
  18. def refresh_remote_account!
  19. return if @account.local?
  20. # While we had the remote account suspended, it could be that
  21. # it got suspended on its origin, too. So, we need to refresh
  22. # it straight away so it gets marked as remotely suspended in
  23. # that case.
  24. @account.update!(last_webfingered_at: nil)
  25. @account = ResolveAccountService.new.call(@account)
  26. # Worth noting that it is possible that the remote has not only
  27. # been suspended, but deleted permanently, in which case
  28. # @account would now be nil.
  29. end
  30. def distribute_update_actor!
  31. return unless @account.local?
  32. account_reach_finder = AccountReachFinder.new(@account)
  33. ActivityPub::DeliveryWorker.push_bulk(account_reach_finder.inboxes) do |inbox_url|
  34. [signed_activity_json, @account.id, inbox_url]
  35. end
  36. end
  37. def merge_into_home_timelines!
  38. @account.followers_for_local_distribution.find_each do |follower|
  39. FeedManager.instance.merge_into_home(@account, follower)
  40. end
  41. end
  42. def merge_into_list_timelines!
  43. @account.lists_for_local_distribution.find_each do |list|
  44. FeedManager.instance.merge_into_list(@account, list)
  45. end
  46. end
  47. def publish_media_attachments!
  48. attachment_names = MediaAttachment.attachment_definitions.keys
  49. @account.media_attachments.find_each do |media_attachment|
  50. attachment_names.each do |attachment_name|
  51. attachment = media_attachment.public_send(attachment_name)
  52. styles = [:original] | attachment.styles.keys
  53. next if attachment.blank?
  54. styles.each do |style|
  55. case Paperclip::Attachment.default_options[:storage]
  56. when :s3
  57. begin
  58. attachment.s3_object(style).acl.put(acl: Paperclip::Attachment.default_options[:s3_permissions])
  59. rescue Aws::S3::Errors::NoSuchKey
  60. Rails.logger.warn "Tried to change acl on non-existent key #{attachment.s3_object(style).key}"
  61. end
  62. when :fog
  63. # Not supported
  64. when :filesystem
  65. begin
  66. FileUtils.chmod(0o666 & ~File.umask, attachment.path(style)) unless attachment.path(style).nil?
  67. rescue Errno::ENOENT
  68. Rails.logger.warn "Tried to change permission on non-existent file #{attachment.path(style)}"
  69. end
  70. end
  71. CacheBusterWorker.perform_async(attachment.path(style)) if Rails.configuration.x.cache_buster_enabled
  72. end
  73. end
  74. end
  75. end
  76. def signed_activity_json
  77. @signed_activity_json ||= Oj.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account))
  78. end
  79. end