about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/lib/command_tag/command/account_tools.rb44
-rw-r--r--app/services/remove_status_service.rb2
2 files changed, 46 insertions, 0 deletions
diff --git a/app/lib/command_tag/command/account_tools.rb b/app/lib/command_tag/command/account_tools.rb
index a2f24789f..b433c32d4 100644
--- a/app/lib/command_tag/command/account_tools.rb
+++ b/app/lib/command_tag/command/account_tools.rb
@@ -11,6 +11,37 @@ module CommandTag::Command::AccountTools
 
   alias handle_acct_at_start handle_account_at_start
 
+  def handle_delete_before_save(args)
+    unless args
+      RemovalWorker.perform_async(@parent.id, immediate: true) if author_of_parent? && status_text_blank?
+      return
+    end
+
+    args.flat_map(&:split).uniq.each do |id|
+      if id.match?(/\A\d+\z/)
+        object = @account.statuses.find_by(id: id)
+      elsif id.start_with?('https://')
+        begin
+          object = ActivityPub::TagManager.instance.uri_to_resource(id, Status)
+          if object.blank? && ActivityPub::TagManager.instance.local_uri?(id)
+            id = Addressable::URI.parse(id)&.normalized_path&.sub(/\A.*\/([^\/]*)\/*/, '\1')
+            next unless id.present? && id.match?(/\A\d+\z/)
+
+            object = find_status_or_create_stub(id)
+          end
+        rescue Addressable::URI::InvalidURIError
+          next
+        end
+      end
+
+      next if object.blank? || object.account_id != @account.id
+
+      RemovalWorker.perform_async(object.id, immediate: true, unpublished: true)
+    end
+  end
+
+  alias handle_destroy_before_save handle_delete_before_save
+
   private
 
   def handle_account_set(args)
@@ -34,4 +65,17 @@ module CommandTag::Command::AccountTools
       end
     end
   end
+
+  def find_status_or_create_stub(id)
+    status_params = {
+      id: id,
+      account: @account,
+      text: '(Deleted)',
+      local: true,
+      visibility: :public,
+      local_only: false,
+      published: false,
+    }
+    Status.where(id: id).first_or_create(status_params)
+  end
 end
diff --git a/app/services/remove_status_service.rb b/app/services/remove_status_service.rb
index 6fd860628..4d3dc13db 100644
--- a/app/services/remove_status_service.rb
+++ b/app/services/remove_status_service.rb
@@ -19,6 +19,8 @@ class RemoveStatusService < BaseService
     @reblogs  = status.reblogs.includes(:account).to_a
     @options  = options
 
+    return unless status.published? || @options[:unpublished]
+
     RedisLock.acquire(lock_options) do |lock|
       if lock.acquired?
         remove_from_self if status.account.local?