FEATURE: Per-category default "slow mode".. (PR #13537)

…as discussed here: Slow mode for a category - feature - Discourse Meta

I wasn’t sure whether to use register_custom_field_type or a regular database column, so I went with a custom field type for simplicity.

This change only adds support for indefinite “slow mode” – I couldn’t think of a use-case for auto-remove-after-specific-time (and it would have taken longer :upside_down_face:).

GitHub

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

Thank you for the pull reqeust.

I wasn’t sure whether to use register_custom_field_type or a regular database column

Custom fields are usually only used by plugins to extend certain core behaviours. Therefore, the new category option should be implemented using a database column.

Custom fields are usually only used by plugins to extend certain core behaviours. Therefore, the new category option should be implemented using a database column.

OK, I’ll switch it over. Thanks for the feedback!

OK @tgxworld, I think I got it going as a DB column! Any further changes you’d like?

Let’s ship this column as part of CategorySerializer only since the column is not useful in a list.

  describe 'auto slow mode' do
    it 'should set slow mode automatically' do
      category = Fabricate(:category_with_definition, 
        created_at: 1.minute.ago,
        default_slow_mode_seconds: 1800
      )
      
      post1 = create_post(category: category)
      topic = post1.topic

      expect(topic.reload.slow_mode_seconds).to eq(1800)
    end
  end

Let’s update slow mode like how we do it for autoclose: discourse/topic.rb at f26acb4b634e148bf0c1f1dfc158859329e4beae · discourse/discourse · GitHub

@mintsaxon Thank you so much for working on this. I think we’re getting close but there are a couple of things that need to be resolved first.

I wasn’t sure if you meant “how we do it for autoclose” in terms of “setting a topic timer”, or just “putting it in models/topic.rb as a separate method” – I did the latter because a) it was easier :sweat_smile: and b) as per the original commit message, I can’t imagine the use-case for having time-limited auto “slow mode” in a category.

All right, I think I made all those changes, many thanks for the review :pray: Any more?

      self.slow_mode_seconds = self.category.default_slow_mode_seconds

Hi @mintsaxon, I’ve made the required changes in FEATURE: Per-category default slow mode duration for topics. by tgxworld · Pull Request #13666 · discourse/discourse · GitHub and will merge this on monday. Thank you so much for your contribution :+1: