UX: Merge settings related to muted tags. (#7656)

UX: Merge settings related to muted tags. (#7656)

diff --git a/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6 b/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6
index 0be1508..d45e3fa 100644
--- a/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6
+++ b/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6
@@ -29,6 +29,11 @@ export default Ember.Controller.extend(PreferencesTabController, {
     return this.get("currentUser.id") === this.get("model.id");
   },
 
+  @computed("siteSettings.remove_muted_tags_from_latest")
+  hideMutedTags() {
+    return this.siteSettings.remove_muted_tags_from_latest !== "never";
+  },
+
   canSave: Ember.computed.or("canSee", "currentUser.admin"),
 
   actions: {
diff --git a/app/assets/javascripts/discourse/templates/preferences/categories.hbs b/app/assets/javascripts/discourse/templates/preferences/categories.hbs
index f76b48e..aaf5572 100644
--- a/app/assets/javascripts/discourse/templates/preferences/categories.hbs
+++ b/app/assets/javascripts/discourse/templates/preferences/categories.hbs
@@ -33,7 +33,7 @@
     <label>{{d-icon "d-muted"}} {{i18n 'user.muted_categories'}}</label>
     {{category-selector categories=model.mutedCategories blacklist=selectedCategories}}
   </div>
-  <div class="instructions">{{i18n 'user.muted_categories_instructions'}}</div>
+  <div class="instructions">{{i18n (if hideMutedTags 'user.muted_categories_instructions' 'user.muted_categories_instructions_dont_hide')}}</div>
   {{#if canSee}}
     <div class="controls">
       <a href="{{unbound model.mutedTopicsPath}}">{{i18n 'user.muted_topics_link'}}</a>
diff --git a/app/models/remove_muted_tags_from_latest_site_setting.rb b/app/models/remove_muted_tags_from_latest_site_setting.rb
new file mode 100644
index 0000000..5c23198
--- /dev/null
+++ b/app/models/remove_muted_tags_from_latest_site_setting.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+require_dependency 'enum_site_setting'
+
+class RemoveMutedTagsFromLatestSiteSetting < EnumSiteSetting
+
+  ALWAYS ||= "always"
+  ONLY_MUTED ||= "only_muted"
+  NEVER ||= "never"
+
+  def self.valid_value?(val)
+    values.any? { |v| v[:value] == val }
+  end
+
+  def self.values
+    @values ||= [
+      { name: "admin.tags.remove_muted_tags_from_latest.always", value: ALWAYS },
+      { name: "admin.tags.remove_muted_tags_from_latest.only_muted", value: ONLY_MUTED },
+      { name: "admin.tags.remove_muted_tags_from_latest.never", value: NEVER }
+    ]
+  end
+
+  def self.translate_names?
+    true
+  end
+end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index e8741f3..1fef32c 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -844,6 +844,7 @@ en:
 
       muted_categories: "Muted"
       muted_categories_instructions: "You will not be notified of anything about new topics in these categories, and they will not appear on the categories or latest pages."
+      muted_categories_instructions_dont_hide: "You will not be notified of anything about new topics in these categories."
       no_category_access: "As a moderator you have limited category access, save is disabled."
       delete_account: "Delete My Account"
       delete_account_confirm: "Are you sure you want to permanently delete your account? This action cannot be undone!"
@@ -3007,6 +3008,12 @@ en:
       title: "Discourse Admin"
       moderator: "Moderator"
 
+      tags:
+        remove_muted_tags_from_latest:
+          always: "always"
+          only_muted: "when used alone or with other muted tags"
+          never: "never"
+
       reports:
         title: "List of available reports"
 
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index fb67313..7efd5d3 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2019,7 +2019,6 @@ en:
     min_trust_level_to_tag_topics: "Minimum trust level required to tag topics"
     suppress_overlapping_tags_in_list: "If tags match exact words in topic titles, don't show the tag"
     remove_muted_tags_from_latest: "Don't show topics tagged only with muted tags in the latest topic list."
-    mute_other_present_tags: "Don't show topics tagged with both muted and unmuted tags in the latest topic list."
     force_lowercase_tags: "Force all new tags to be entirely lowercase."
 
     company_name: "Company Name"
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 1a9e57d..a809138 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -2059,9 +2059,10 @@ tags:
     default: false
     client: true
   remove_muted_tags_from_latest:
-    default: false
-  mute_other_present_tags:
-    default: true
+    client: true
+    type: enum
+    default: always
+    enum: RemoveMutedTagsFromLatestSiteSetting
   force_lowercase_tags:
     default: true
     client: true
diff --git a/db/migrate/20190531101648_merge_remove_muted_tags_from_latest_site_settings.rb b/db/migrate/20190531101648_merge_remove_muted_tags_from_latest_site_settings.rb
new file mode 100644
index 0000000..0a7629a
--- /dev/null
+++ b/db/migrate/20190531101648_merge_remove_muted_tags_from_latest_site_settings.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class MergeRemoveMutedTagsFromLatestSiteSettings < ActiveRecord::Migration[5.2]
+  def up
+    execute "UPDATE site_settings SET value = 'always', data_type = 7 WHERE name = 'remove_muted_tags_from_latest' AND value = 't'"
+    execute "UPDATE site_settings SET value = 'never',  data_type = 7 WHERE name = 'remove_muted_tags_from_latest' AND value = 'f'"
+    execute "DELETE FROM site_settings WHERE name = 'mute_other_present_tags'"
+  end
+
+  def down
+    raise ActiveRecord::IrreversibleMigration
+  end
+end
diff --git a/lib/topic_query.rb b/lib/topic_query.rb
index 34b4c26..3354795 100644
--- a/lib/topic_query.rb
+++ b/lib/topic_query.rb
@@ -875,7 +875,7 @@ class TopicQuery
     list
   end
   def remove_muted_tags(list, user, opts = nil)
-    if user.nil? || !SiteSetting.tagging_enabled || !SiteSetting.remove_muted_tags_from_latest
+    if user.nil? || !SiteSetting.tagging_enabled || SiteSetting.remove_muted_tags_from_latest == 'never'
       return list
     end
 
@@ -896,7 +896,7 @@ class TopicQuery
       return list
     end
 
-    if SiteSetting.mute_other_present_tags
+    if SiteSetting.remove_muted_tags_from_latest == 'always'
       list = list.where("
         NOT EXISTS(
           SELECT 1
diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb
index 56b8b6c..273c640 100644
--- a/spec/components/topic_query_spec.rb
+++ b/spec/components/topic_query_spec.rb
@@ -244,7 +244,7 @@ describe TopicQuery do
   context 'muted tags' do
     it 'is removed from new and latest lists' do
       SiteSetting.tagging_enabled = true
-      SiteSetting.remove_muted_tags_from_latest = true
+      SiteSetting.remove_muted_tags_from_latest = 'always'
 
       muted_tag, other_tag = Fabricate(:tag), Fabricate(:tag)
 
@@ -263,13 +263,21 @@ describe TopicQuery do
       topic_ids = topic_query.list_new.topics.map(&:id)
       expect(topic_ids).to contain_exactly(tagged_topic.id, untagged_topic.id)
 
-      SiteSetting.mute_other_present_tags = false
+      SiteSetting.remove_muted_tags_from_latest = 'only_muted'
 
       topic_ids = topic_query.list_latest.topics.map(&:id)
-      expect(topic_ids).to contain_exactly(muted_tagged_topic.id, tagged_topic.id, untagged_topic.id)
+      expect(topic_ids).to contain_exactly(tagged_topic.id, muted_tagged_topic.id, untagged_topic.id)
 
       topic_ids = topic_query.list_new.topics.map(&:id)
-      expect(topic_ids).to contain_exactly(muted_tagged_topic.id, tagged_topic.id, untagged_topic.id)
+      expect(topic_ids).to contain_exactly(tagged_topic.id, muted_tagged_topic.id, untagged_topic.id)
+
+      SiteSetting.remove_muted_tags_from_latest = 'never'
+
+      topic_ids = topic_query.list_latest.topics.map(&:id)

[... diff too long, it was truncated ...]

GitHub sha: c1e7a1b2

1 Like