Add sensitive words setting

This commit is contained in:
KMY 2023-07-27 12:47:33 +09:00
parent 0dbc070037
commit cd00d7f533
12 changed files with 128 additions and 1 deletions

View file

@ -127,6 +127,7 @@ class UpdateStatusService < BaseService
@status.markdown = @options[:markdown] || false
@status.sensitive = @options[:sensitive] || @options[:spoiler_text].present? if @options.key?(:sensitive) || @options.key?(:spoiler_text)
@status.language = valid_locale_cascade(@options[:language], @status.language, @status.account.user&.preferred_posting_language, I18n.default_locale)
process_sensitive_words
# We raise here to rollback the entire transaction
raise NoChangesSubmittedError unless significant_changes?
@ -137,6 +138,13 @@ class UpdateStatusService < BaseService
@status.save!
end
def process_sensitive_words
return unless [:public, :public_unlisted, :login].include?(@status.visibility&.to_sym) && Admin::SensitiveWord.sensitive?(@status.text, @status.spoiler_text || '')
@status.text = Admin::SensitiveWord.modified_text(@status.text, @status.spoiler_text)
@status.spoiler_text = I18n.t('admin.sensitive_words.alert')
end
def update_expiration!
UpdateStatusExpirationService.new.call(@status)
end