From f08f880f584271a922a0d8d3759e634d67947d12 Mon Sep 17 00:00:00 2001 From: ThibG Date: Wed, 25 Mar 2020 22:40:58 +0100 Subject: Fix media not being marked sensitive when client sets a CW but no text (#13277) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mastodon enforces the “sensitive” flag on media attachments whenever a toot is posted with a Content Warning. However, it does so *after* potentially converting the Content Warning to toot text (when there is no toot text), which leads to inconsistent and surprising behavior for API clients. This commit fixes this inconsistency. --- app/services/post_status_service.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (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 c61b3baa2..0a383d6a3 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -48,6 +48,7 @@ class PostStatusService < BaseService private def preprocess_attributes! + @sensitive = (@options[:sensitive].nil? ? @account.user&.setting_default_sensitive : @options[:sensitive]) || @options[:spoiler_text].present? @text = @options.delete(:spoiler_text) if @text.blank? && @options[:spoiler_text].present? @visibility = @options[:visibility] || @account.user&.setting_default_privacy @visibility = :unlisted if @visibility&.to_sym == :public && @account.silenced? @@ -157,7 +158,7 @@ class PostStatusService < BaseService media_attachments: @media || [], thread: @in_reply_to, poll_attributes: poll_attributes, - sensitive: (@options[:sensitive].nil? ? @account.user&.setting_default_sensitive : @options[:sensitive]) || @options[:spoiler_text].present?, + sensitive: @sensitive, spoiler_text: @options[:spoiler_text] || '', visibility: @visibility, language: language_from_option(@options[:language]) || @account.user&.setting_default_language&.presence || LanguageDetector.instance.detect(@text, @account), -- cgit From d98fabf2ee44c2c25775066abda46552ab05993e Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Fri, 27 Mar 2020 22:28:39 +0100 Subject: Fix crash when posting with a CW but no text nor media --- app/services/post_status_service.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 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 39b834604..250d0e8ed 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -50,11 +50,11 @@ class PostStatusService < BaseService def preprocess_attributes! if @text.blank? && @options[:spoiler_text].present? @text = '.' - if @media.find(&:video?) || @media.find(&:gifv?) + if @media&.find(&:video?) || @media&.find(&:gifv?) @text = '📹' - elsif @media.find(&:audio?) + elsif @media&.find(&:audio?) @text = '🎵' - elsif @media.find(&:image?) + elsif @media&.find(&:image?) @text = '🖼' end end -- cgit