about summary refs log tree commit diff
path: root/app/lib/command_tag
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib/command_tag')
-rw-r--r--app/lib/command_tag/command/status_tools.rb14
-rw-r--r--app/lib/command_tag/processor.rb15
2 files changed, 29 insertions, 0 deletions
diff --git a/app/lib/command_tag/command/status_tools.rb b/app/lib/command_tag/command/status_tools.rb
index 1cdb90e4a..5cc11dde2 100644
--- a/app/lib/command_tag/command/status_tools.rb
+++ b/app/lib/command_tag/command/status_tools.rb
@@ -1,5 +1,19 @@
 # frozen_string_literal: true
 module CommandTag::Command::StatusTools
+  def handle_boost_once_at_start(args)
+    return unless @parent.present? && StatusPolicy.new(@account, @parent).reblog?
+
+    status = ReblogService.new.call(
+      @account, @parent,
+      visibility: @status.visibility,
+      spoiler_text: args.join(' ').presence || @status.spoiler_text
+    )
+  end
+
+  alias handle_reblog_at_start handle_boost_once_at_start
+  alias handle_rb_at_start handle_boost_once_at_start
+  alias handle_rt_at_start handle_boost_once_at_start
+
   def handle_article_before_save(args)
     return unless author_of_status? && args.present?
 
diff --git a/app/lib/command_tag/processor.rb b/app/lib/command_tag/processor.rb
index 2c33b5f83..9edcb58ba 100644
--- a/app/lib/command_tag/processor.rb
+++ b/app/lib/command_tag/processor.rb
@@ -12,6 +12,12 @@
 
 require_relative 'commands'
 
+class CommandTag::Break < Mastodon::Error
+  def initialize(msg = 'A handler stopped execution.')
+    super
+  end
+end
+
 class CommandTag::Processor
   include Redisable
   include ImgProxyHelper
@@ -83,6 +89,8 @@ class CommandTag::Processor
 
     execute_statements(:at_end)
     all_handlers!(:shutdown)
+  rescue CommandTag::Break
+    nil
   rescue StandardError => e
     @status.update(published: false)
     @status.destroy
@@ -247,6 +255,13 @@ class CommandTag::Processor
     @status.destroy
   end
 
+  def replace_status!(new_status)
+    return if new_status.blank?
+
+    destroy_status!
+    @status = new_status
+  end
+
   def normalize(text)
     text.to_s.strip.downcase
   end