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.

99 lines
3.0 KiB

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