about summary refs log tree commit diff
path: root/app/services/post_status_service.rb
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-07-19 18:50:24 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:43:59 -0500
commit21438b54bdaf3c557ec9ebbc482a2c418d8c64f8 (patch)
treee577d047af196823227e675dea52b2fc2fa842c6 /app/services/post_status_service.rb
parent8c8ad0ac0ed0d3e67f3e521068b59edd4054f1e9 (diff)
[Feature] Add manual publishing option
Diffstat (limited to 'app/services/post_status_service.rb')
-rw-r--r--app/services/post_status_service.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index c52ca4a9b..5ddc1aeeb 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -23,6 +23,7 @@ class PostStatusService < BaseService
   # @option [Status] :status Edit an existing status
   # @option [Enumerable] :mentions Optional array of Mentions to include
   # @option [Enumerable] :tags Option array of tag names to include
+  # @option [Boolean] :publish If true, status will be published
   # @return [Status]
   def call(account, options = {})
     @account     = account
@@ -30,6 +31,8 @@ class PostStatusService < BaseService
     @text        = @options[:text] || ''
     @in_reply_to = @options[:thread]
 
+    @options[:publish] ||= !account.user&.setting_manual_publish
+
     raise Mastodon::NotPermittedError if different_author?
 
     @tag_names   = (@options[:tags] || []).select { |tag| tag =~ /\A(#{Tag::HASHTAG_NAME_RE})\z/i }
@@ -47,7 +50,7 @@ class PostStatusService < BaseService
     else
       process_status!
       postprocess_status!
-      bump_potential_friendship!
+      bump_potential_friendship! if @options[:publish]
     end
 
     redis.setex(idempotency_key, 3_600, @status.id) if idempotency_given?
@@ -86,7 +89,7 @@ class PostStatusService < BaseService
     end
 
     process_hashtags_service.call(@status, nil, @tag_names)
-    process_mentions_service.call(@status, mentions: @mentions)
+    process_mentions_service.call(@status, mentions: @mentions, deliver: @options[:publish])
   end
 
   def schedule_status!
@@ -109,6 +112,9 @@ class PostStatusService < BaseService
   def postprocess_status!
     LinkCrawlWorker.perform_async(@status.id) unless @status.spoiler_text?
     DistributionWorker.perform_async(@status.id)
+
+    return unless @options[:publish]
+
     ActivityPub::DistributionWorker.perform_async(@status.id) unless @status.local_only?
     PollExpirationNotifyWorker.perform_at(@status.poll.expires_at, @status.poll.id) if @status.poll
   end
@@ -188,6 +194,7 @@ class PostStatusService < BaseService
       visibility: @visibility,
       language: language_from_option(@options[:language]) || @account.user&.setting_default_language&.presence || LanguageDetector.instance.detect(@text, @account),
       application: @options[:application],
+      published: @options[:publish],
       content_type: @options[:content_type] || @account.user&.setting_default_content_type,
       rate_limit: @options[:with_rate_limit],
     }.compact