From 3e57d03573d267e54da66effdd502b3372f4bbd9 Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Sat, 1 Aug 2020 20:20:29 -0500 Subject: [Privacy, Command Tags] Add advanced deletes --- app/lib/command_tag/command/account_tools.rb | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'app/lib/command_tag') 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 -- cgit