Skip to content
Permalink
Browse files

Fix media not being marked sensitive when client sets a CW but no text (

#13277)

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.
  • Loading branch information
ThibG committed Mar 25, 2020
1 parent 858d0dd commit f08f880f584271a922a0d8d3759e634d67947d12
Showing with 9 additions and 1 deletion.
  1. +2 −1 app/services/post_status_service.rb
  2. +7 −0 spec/services/post_status_service_spec.rb
@@ -48,6 +48,7 @@ def call(account, options = {})
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 @@ def status_attributes
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),
@@ -79,6 +79,13 @@
expect(status.spoiler_text).to eq spoiler_text
end

it 'creates a sensitive status when there is a CW but no text' do
status = subject.call(Fabricate(:account), text: '', spoiler_text: 'foo')

expect(status).to be_persisted
expect(status).to be_sensitive
end

it 'creates a status with empty default spoiler text' do
status = create_status_with_options(spoiler_text: nil)

0 comments on commit f08f880

Please sign in to comment.
You can’t perform that action at this time.