From 21438b54bdaf3c557ec9ebbc482a2c418d8c64f8 Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Sun, 19 Jul 2020 18:50:24 -0500 Subject: [Feature] Add manual publishing option --- app/services/post_status_service.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'app/services/post_status_service.rb') 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 -- cgit