Fix invalid language resulting in no fallback being set on statuses (#17722)

This commit is contained in:
Eugen Rochko 2022-03-09 08:46:05 +01:00 committed by GitHub
parent 8f6c67bfde
commit c0327ff31f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View file

@ -241,6 +241,15 @@ module LanguagesHelper
code code
end end
def valid_locale_cascade(*arr)
arr.each do |str|
locale = valid_locale_or_nil(str)
return locale if locale.present?
end
nil
end
def valid_locale?(locale) def valid_locale?(locale)
locale.present? && SUPPORTED_LOCALES.key?(locale.to_sym) locale.present? && SUPPORTED_LOCALES.key?(locale.to_sym)
end end

View file

@ -162,7 +162,7 @@ class PostStatusService < BaseService
sensitive: @sensitive, sensitive: @sensitive,
spoiler_text: @options[:spoiler_text] || '', spoiler_text: @options[:spoiler_text] || '',
visibility: @visibility, visibility: @visibility,
language: valid_locale_or_nil(@options[:language].presence || @account.user&.preferred_posting_language || I18n.default_locale), language: valid_locale_cascade(@options[:language], @account.user&.preferred_posting_language, I18n.default_locale),
application: @options[:application], application: @options[:application],
rate_limit: @options[:with_rate_limit], rate_limit: @options[:with_rate_limit],
}.compact }.compact

View file

@ -94,7 +94,7 @@ class UpdateStatusService < BaseService
@status.text = @options[:text].presence || @options.delete(:spoiler_text) || '' if @options.key?(:text) @status.text = @options[:text].presence || @options.delete(:spoiler_text) || '' if @options.key?(:text)
@status.spoiler_text = @options[:spoiler_text] || '' if @options.key?(:spoiler_text) @status.spoiler_text = @options[:spoiler_text] || '' if @options.key?(:spoiler_text)
@status.sensitive = @options[:sensitive] || @options[:spoiler_text].present? if @options.key?(:sensitive) || @options.key?(:spoiler_text) @status.sensitive = @options[:sensitive] || @options[:spoiler_text].present? if @options.key?(:sensitive) || @options.key?(:spoiler_text)
@status.language = valid_locale_or_nil(@options[:language] || @status.language || @status.account.user&.preferred_posting_language || I18n.default_locale) @status.language = valid_locale_cascade(@options[:language], @status.language, @status.account.user&.preferred_posting_language, I18n.default_locale)
@status.edited_at = Time.now.utc @status.edited_at = Time.now.utc
@status.save! @status.save!