Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Per-category default slow mode duration for topics. #13666

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -138,4 +138,10 @@ export default buildCategoryPanel("settings", {
let hours = minutes ? minutes / 60 : null;
this.set("category.auto_close_hours", hours);
},

@action
onDefaultSlowModeDurationChange(minutes) {
let seconds = minutes ? minutes * 60 : null;
this.set("category.default_slow_mode_seconds", seconds);
},
});
6 changes: 6 additions & 0 deletions app/assets/javascripts/discourse/app/models/category.js
Expand Up @@ -177,6 +177,11 @@ const Category = RestModel.extend({
return topicCount;
},

@discourseComputed("default_slow_mode_seconds")
defaultSlowModeMinutes(seconds) {
return seconds ? seconds / 60 : null;
},

save() {
const id = this.id;
const url = id ? `/categories/${id}` : "/categories";
Expand All @@ -193,6 +198,7 @@ const Category = RestModel.extend({
auto_close_based_on_last_post: this.get(
"auto_close_based_on_last_post"
),
default_slow_mode_seconds: this.default_slow_mode_seconds,
position: this.position,
email_in: this.email_in,
email_in_allow_strangers: this.email_in_allow_strangers,
Expand Down
Expand Up @@ -116,6 +116,21 @@
</label>
</section>

<section class="field default-slow-mode">
<div class="control-group">
<label for="category-default-slow-mode">
{{i18n "category.default_slow_mode"}}
</label>
<div class="category-default-slow-mode-seconds">
{{relative-time-picker
id="category-default-slow-mode"
durationMinutes=category.defaultSlowModeMinutes
hiddenIntervals=hiddenRelativeIntervals
onChange=(action "onDefaultSlowModeDurationChange")}}
</div>
</div>
</section>

<section class="field auto-close">
<div class="control-group">
<label for="topic-auto-close">
Expand Down
3 changes: 2 additions & 1 deletion app/assets/stylesheets/common/base/edit-category.scss
Expand Up @@ -158,7 +158,8 @@ div.edit-category {
padding: 0 1.5em 2em 0;
}

.category-topic-auto-close-hours {
.category-topic-auto-close-hours,
.category-default-slow-mode-seconds {
width: 200px;
}
}
Expand Down
1 change: 1 addition & 0 deletions app/controllers/categories_controller.rb
Expand Up @@ -298,6 +298,7 @@ def category_params
:mailinglist_mirror,
:all_topics_wiki,
:allow_unlimited_owner_edits_on_first_post,
:default_slow_mode_seconds,
:parent_category_id,
:auto_close_hours,
:auto_close_based_on_last_post,
Expand Down
1 change: 1 addition & 0 deletions app/models/category.rb
Expand Up @@ -1027,6 +1027,7 @@ def on_custom_fields_change
# read_only_banner :string
# default_list_filter :string(20) default("all")
# allow_unlimited_owner_edits_on_first_post :boolean default(FALSE), not null
# default_slow_mode_seconds :integer
#
# Indexes
#
Expand Down
7 changes: 7 additions & 0 deletions app/models/topic.rb
Expand Up @@ -334,6 +334,7 @@ def recover!(recovered_by = nil)

if category_id_changed? || new_record?
inherit_auto_close_from_category
inherit_slow_mode_from_category
end
end

Expand Down Expand Up @@ -1251,6 +1252,12 @@ def self.ensure_consistency!
end
end

def inherit_slow_mode_from_category
if self.category&.default_slow_mode_seconds
self.slow_mode_seconds = self.category&.default_slow_mode_seconds
end
end

def inherit_auto_close_from_category(timer_type: :close)
auto_close_hours = self.category&.auto_close_hours

Expand Down
3 changes: 2 additions & 1 deletion app/serializers/category_serializer.rb
Expand Up @@ -20,7 +20,8 @@ class CategorySerializer < SiteCategorySerializer
:custom_fields,
:topic_featured_link_allowed,
:search_priority,
:reviewable_by_group_name
:reviewable_by_group_name,
:default_slow_mode_seconds

def reviewable_by_group_name
object.reviewable_by_group.name
Expand Down
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Expand Up @@ -3226,6 +3226,7 @@ en:
position_disabled: "Categories will be displayed in order of activity. To control the order of categories in lists, "
position_disabled_click: 'enable the "fixed category positions" setting.'
minimum_required_tags: "Minimum number of tags required in a topic:"
default_slow_mode: 'Enable "Slow Mode" for new topics in this category.'
parent: "Parent Category"
num_auto_bump_daily: "Number of open topics to automatically bump daily:"
navigate_to_first_post_after_read: "Navigate to first post after topics are read"
Expand Down
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddDefaultAutoCloseSecondsToCategory < ActiveRecord::Migration[6.1]
def change
add_column :categories, :default_slow_mode_seconds, :integer
end
end
7 changes: 7 additions & 0 deletions spec/requests/api/schemas/json/category_create_response.json
Expand Up @@ -170,6 +170,12 @@
"allow_unlimited_owner_edits_on_first_post": {
"type": "boolean"
},
"default_slow_mode_seconds": {
"type": [
"string",
"null"
]
},
"group_permissions": {
"type": "array",
"items": [
Expand Down Expand Up @@ -274,6 +280,7 @@
"auto_close_hours",
"auto_close_based_on_last_post",
"allow_unlimited_owner_edits_on_first_post",
"default_slow_mode_seconds",
"group_permissions",
"email_in",
"email_in_allow_strangers",
Expand Down
7 changes: 7 additions & 0 deletions spec/requests/api/schemas/json/category_update_response.json
Expand Up @@ -173,6 +173,12 @@
"allow_unlimited_owner_edits_on_first_post": {
"type": "boolean"
},
"default_slow_mode_seconds": {
"type": [
"string",
"null"
]
},
"group_permissions": {
"type": "array",
"items": [
Expand Down Expand Up @@ -277,6 +283,7 @@
"auto_close_hours",
"auto_close_based_on_last_post",
"allow_unlimited_owner_edits_on_first_post",
"default_slow_mode_seconds",
"group_permissions",
"email_in",
"email_in_allow_strangers",
Expand Down