Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Fix invalid language resulting in no fallback being set on statuses (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron authored Mar 9, 2022
1 parent 8f6c67b commit c0327ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/helpers/languages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ def valid_locale_or_nil(str)
code
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)
locale.present? && SUPPORTED_LOCALES.key?(locale.to_sym)
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/post_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def status_attributes
sensitive: @sensitive,
spoiler_text: @options[:spoiler_text] || '',
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],
rate_limit: @options[:with_rate_limit],
}.compact
Expand Down
2 changes: 1 addition & 1 deletion app/services/update_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def update_immediate_attributes!
@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.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.save!
Expand Down

0 comments on commit c0327ff

Please sign in to comment.