From ac0053f491e6604f943ecb7d10f400d7d1d80d4a Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 16 Jul 2018 18:10:22 +1000 Subject: [PATCH] FEATURE: navigate to first post and auto bump category settings ### navigate_to_first_post_after_read setting for categories When enabled on categories logged on users will return to OP after reading the entire category. (useful for documentation categories) ### num_auto_bump_daily Set a number of topics that will automatically bump daily on a category. - Every 15 minutes we will check if any category has this setting - Categories with the setting are shuffled - We exclude pinned, closed, category description and archived topics - Maximum of 1 topic for the list of categories is bumped till limit reached per category - We always try to bump oldest first - Limit is elastic using a RateLimiter that ensures that we only bump N per day Also some minor organisation on category settings Froze strings on category.rb --- .../discourse/models/category.js.es6 | 5 +- .../javascripts/discourse/models/topic.js.es6 | 17 +- .../components/edit-category-settings.hbs | 64 +++++--- app/assets/stylesheets/common/base/modal.scss | 8 +- app/controllers/categories_controller.rb | 1 + app/jobs/scheduled/periodical_updates.rb | 8 + app/models/category.rb | 150 ++++++++++++------ app/serializers/basic_category_serializer.rb | 3 +- config/locales/client.en.yml | 6 +- ..._to_first_post_after_read_to_categories.rb | 5 + spec/models/category_spec.rb | 40 +++++ spec/requests/categories_controller_spec.rb | 9 +- test/javascripts/models/topic-test.js.es6 | 17 ++ 13 files changed, 241 insertions(+), 92 deletions(-) create mode 100644 db/migrate/20180716062405_add_navigate_to_first_post_after_read_to_categories.rb diff --git a/app/assets/javascripts/discourse/models/category.js.es6 b/app/assets/javascripts/discourse/models/category.js.es6 index 8a5997f4a14..0afa3fd9bc3 100644 --- a/app/assets/javascripts/discourse/models/category.js.es6 +++ b/app/assets/javascripts/discourse/models/category.js.es6 @@ -115,7 +115,10 @@ const Category = RestModel.extend({ default_view: this.get("default_view"), subcategory_list_style: this.get("subcategory_list_style"), default_top_period: this.get("default_top_period"), - minimum_required_tags: this.get("minimum_required_tags") + minimum_required_tags: this.get("minimum_required_tags"), + navigate_to_first_post_after_read: this.get( + "navigate_to_first_post_after_read" + ) }, type: id ? "PUT" : "POST" }); diff --git a/app/assets/javascripts/discourse/models/topic.js.es6 b/app/assets/javascripts/discourse/models/topic.js.es6 index a47192b7e71..68be7f9b016 100644 --- a/app/assets/javascripts/discourse/models/topic.js.es6 +++ b/app/assets/javascripts/discourse/models/topic.js.es6 @@ -212,11 +212,18 @@ const Topic = RestModel.extend({ }.property("url", "last_read_post_number"), lastUnreadUrl: function() { - const postNumber = Math.min( - this.get("last_read_post_number") + 1, - this.get("highest_post_number") - ); - return this.urlForPostNumber(postNumber); + const highest = this.get("highest_post_number"); + const lastRead = this.get("last_read_post_number"); + + if (highest <= lastRead) { + if (this.get("category.navigate_to_first_post_after_read")) { + return this.urlForPostNumber(1); + } else { + return this.urlForPostNumber(lastRead + 1); + } + } else { + return this.urlForPostNumber(lastRead + 1); + } }.property("url", "last_read_post_number", "highest_post_number"), lastPostUrl: function() { diff --git a/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs b/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs index e08271dfff4..778ddcbfda7 100644 --- a/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs +++ b/app/assets/javascripts/discourse/templates/components/edit-category-settings.hbs @@ -1,3 +1,19 @@ +{{#if showPositionInput}} +
+ +
+{{/if}} + +{{#unless showPositionInput}} +
+ {{i18n 'category.position_disabled'}} + {{i18n 'category.position_disabled_click'}} +
+{{/unless}} +
- +
+ +
+ {{#if siteSettings.topic_featured_link_enabled}}