Skip to content

A platform for community discussion. Free, open, simple.

UX: Set silence_reason using the system locale

David Taylor4476680d4b07
diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rb
index a542ad60132..081e6e524f0 100644
--- a/lib/new_post_manager.rb
+++ b/lib/new_post_manager.rb
@@ -157,12 +157,14 @@ class NewPostManager
result = manager.enqueue(reason)
- if is_fast_typer?(manager)
- UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.new_user_typed_too_fast"))
- elsif matches_auto_silence_regex?(manager)
- UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.content_matches_auto_silence_regex"))
- elsif reason == :email_spam && is_first_post?(manager)
- UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.email_in_spam_header"))
+ I18n.with_locale(SiteSetting.default_locale) do
+ if is_fast_typer?(manager)
+ UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.new_user_typed_too_fast"))
+ elsif matches_auto_silence_regex?(manager)
+ UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.content_matches_auto_silence_regex"))
+ elsif reason == :email_spam && is_first_post?(manager)
+ UserSilencer.silence(manager.user, Discourse.system_user, keep_posts: true, reason: I18n.t("user.email_in_spam_header"))
+ end
end
result
diff --git a/spec/components/new_post_manager_spec.rb b/spec/components/new_post_manager_spec.rb
index 40bf8693991..983a626e458 100644
--- a/spec/components/new_post_manager_spec.rb
+++ b/spec/components/new_post_manager_spec.rb
@@ -182,6 +182,23 @@ describe NewPostManager do
end
end
+ context 'with a fast typer' do
+ let(:manager) { NewPostManager.new(topic.user, raw: 'this is new post content', topic_id: topic.id, first_post_checks: true) }
+ let(:user) { manager.user }
+
+ before do
+ user.update!(trust_level: 0)
+ end
+
+ it "adds the silence reason in the system locale" do
+ I18n.with_locale(:fr) do # Simulate french user
+ result = NewPostManager.default_handler(manager)
+ end
+ expect(user.silenced?).to eq(true)
+ expect(user.silence_reason).to eq(I18n.t("user.new_user_typed_too_fast", locale: :en))
+ end
+ end
+
end
context "new topic handler" do