A platform for community discussion. Free, open, simple.
FEATURE: Convert watched_precedence_over_muted to default site setting (#35671)
Martin Brennan93862b98dda4
diff --git a/app/models/site_setting.rb b/app/models/site_setting.rbindex b700405c89d..d83e0608550 100644--- a/app/models/site_setting.rb+++ b/app/models/site_setting.rb@@ -74,6 +74,7 @@ class SiteSetting < ActiveRecord::Basedefault_sidebar_link_to_filtered_listdefault_sidebar_show_count_of_new_itemsdefault_composition_mode+ default_watched_precedence_over_muted]extend GlobalPathdiff --git a/app/models/user.rb b/app/models/user.rbindex c0b65436a5a..afb31117007 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -1918,14 +1918,6 @@ class User < ActiveRecord::Basein_any_groups?(SiteSetting.experimental_new_new_view_groups_map)end- def watched_precedence_over_muted- if user_option.watched_precedence_over_muted.nil?- SiteSetting.watched_precedence_over_muted- else- user_option.watched_precedence_over_muted- end- end-def populated_required_custom_fields?UserField.for_all_usersdiff --git a/app/models/user_option.rb b/app/models/user_option.rbindex cd6d9c70749..909badf0687 100644--- a/app/models/user_option.rb+++ b/app/models/user_option.rb@@ -109,6 +109,7 @@ class UserOption < ActiveRecord::Baseself.sidebar_link_to_filtered_list = SiteSetting.default_sidebar_link_to_filtered_listself.sidebar_show_count_of_new_items = SiteSetting.default_sidebar_show_count_of_new_itemsself.composition_mode = SiteSetting.default_composition_mode+ self.watched_precedence_over_muted = SiteSetting.default_watched_precedence_over_mutedtrueend@@ -305,7 +306,7 @@ end# timezone :string# title_count_mode_key :integer default(0), not null# topics_unread_when_closed :boolean default(TRUE), not null-# watched_precedence_over_muted :boolean+# watched_precedence_over_muted :boolean default(FALSE), not null# color_scheme_id :integer# dark_scheme_id :integer# homepage_id :integerdiff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rbindex af7a79e5204..80771ffd289 100644--- a/app/services/post_alerter.rb+++ b/app/services/post_alerter.rb@@ -311,13 +311,6 @@ class PostAlerterenddef category_or_tag_muters(topic)- user_option_condition_sql_fragment =- if SiteSetting.watched_precedence_over_muted- "uo.watched_precedence_over_muted IS false"- else- "(uo.watched_precedence_over_muted IS NULL OR uo.watched_precedence_over_muted IS false)"- end-user_ids_sql = <<~SQLSELECT uo.user_id FROM user_options uoLEFT JOIN topic_users tus ON tus.user_id = uo.user_id AND tus.topic_id = #{topic.id}@@ -327,7 +320,7 @@ class PostAlerterWHERE(tus.id IS NULL OR tus.notification_level != #{TopicUser.notification_levels[:watching]})AND (cu.notification_level = #{CategoryUser.notification_levels[:muted]} OR tu.notification_level = #{TagUser.notification_levels[:muted]})- AND #{user_option_condition_sql_fragment}+ AND uo.watched_precedence_over_muted IS falseSQLUser.where("id IN (#{user_ids_sql})")diff --git a/app/services/site_setting_update_existing_users.rb b/app/services/site_setting_update_existing_users.rbindex 701dabaaafa..5e61d2d88bc 100644--- a/app/services/site_setting_update_existing_users.rb+++ b/app/services/site_setting_update_existing_users.rb@@ -76,6 +76,7 @@ class SiteSettingUpdateExistingUsersdefault_sidebar_link_to_filtered_list: "sidebar_link_to_filtered_list",default_sidebar_show_count_of_new_items: "sidebar_show_count_of_new_items",default_composition_mode: "composition_mode",+ default_watched_precedence_over_muted: "watched_precedence_over_muted",}enddiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 6d9bede6858..0dd8fdd2676 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2685,7 +2685,7 @@ en:force_lowercase_tags: "Force all new tags to be entirely lowercase."create_post_for_category_and_tag_changes: "Create a whisper post when a topic's category or tags change, requires whisper posts to be enabled."automatically_clean_unused_tags: "Automatically delete tags that are not being used on any topics or personal messages on a daily basis."- watched_precedence_over_muted: "Notify me about topics in categories or tags I’m watching that also belong to one I have muted"+ default_watched_precedence_over_muted: "Notify users about topics in categories or tags that they are watching that also belong to one they have muted"company_name: "Name of your company or organization. If left blank, no boilerplate Terms of Service or Privacy Notice will be provided."governing_law: "Specify the jurisdiction that governs the legal aspects of the site, including Terms of Service and Privacy Policy. This is typically the country or state where the company operating the site is registered or conducts business."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 599694afa83..06a140f383f 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -3953,6 +3953,10 @@ user_preferences:default_other_enable_markdown_monospace_font:default: truearea: "posts_and_topics|user_defaults"+ default_watched_precedence_over_muted:+ client: true+ default: false+ area: "categories_and_tags|user_defaults"api:retain_web_hook_events_period_days:@@ -4122,10 +4126,6 @@ tags:default: alwaysenum: RemoveMutedTagsFromLatestSiteSettingarea: "categories_and_tags"- watched_precedence_over_muted:- client: true- default: false- area: "categories_and_tags"force_lowercase_tags:default: truediff --git a/db/migrate/20251016013505_convert_watched_precedence_over_muted_to_default_pref.rb b/db/migrate/20251016013505_convert_watched_precedence_over_muted_to_default_pref.rbnew file mode 100644index 00000000000..69ed17ef768--- /dev/null+++ b/db/migrate/20251016013505_convert_watched_precedence_over_muted_to_default_pref.rb@@ -0,0 +1,36 @@+# frozen_string_literal: true+class ConvertWatchedPrecedenceOverMutedToDefaultPref < ActiveRecord::Migration[8.0]+ def up+ existing_setting_value =+ DB.query_single(+ "SELECT value FROM site_settings WHERE name = 'watched_precedence_over_muted'",+ ).first++ # Data type 5 is boolean+ DB.exec(<<~SQL, setting_value: existing_setting_value) if existing_setting_value+ INSERT INTO site_settings (name, data_type, value, created_at, updated_at)+ VALUES ('default_watched_precedence_over_muted', 5, :setting_value, NOW(), NOW())+ SQL++ preference_value =+ if existing_setting_value.nil?+ # This is the default site setting value for default_watched_precedence_over_muted+ preference_value = false+ else+ preference_value = existing_setting_value == "t"+ end++ DB.exec(<<~SQL, preference_value: preference_value)+ UPDATE user_options+ SET watched_precedence_over_muted = :preference_value+ WHERE watched_precedence_over_muted IS NULL;+ SQL++ change_column_default :user_options, :watched_precedence_over_muted, from: nil, to: false+ change_column_null :user_options, :watched_precedence_over_muted, false+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/db/post_migrate/20251029072625_delete_old_watched_precedence_setting.rb b/db/post_migrate/20251029072625_delete_old_watched_precedence_setting.rbnew file mode 100644index 00000000000..27db5a42eda--- /dev/null+++ b/db/post_migrate/20251029072625_delete_old_watched_precedence_setting.rb@@ -0,0 +1,12 @@+# frozen_string_literal: true+class DeleteOldWatchedPrecedenceSetting < ActiveRecord::Migration[8.0]+ def up+ DB.exec(<<~SQL)+ DELETE FROM site_settings WHERE name = 'watched_precedence_over_muted';+ SQL+ end++ def down+ raise ActiveRecord::IrreversibleMigration+ end+enddiff --git a/frontend/discourse/admin/lib/constants.js b/frontend/discourse/admin/lib/constants.jsindex 15b60f370ed..2706d376e54 100644--- a/frontend/discourse/admin/lib/constants.js+++ b/frontend/discourse/admin/lib/constants.js@@ -90,6 +90,7 @@ export const DEFAULT_USER_PREFERENCES = ["default_sidebar_link_to_filtered_list","default_sidebar_show_count_of_new_items","default_composition_mode",+ "default_watched_precedence_over_muted",];export const MAIN_FONTS = [diff --git a/frontend/discourse/app/controllers/preferences/tracking.js b/frontend/discourse/app/controllers/preferences/tracking.jsindex 8e566b133f8..2560d37ebcd 100644--- a/frontend/discourse/app/controllers/preferences/tracking.js+++ b/frontend/discourse/app/controllers/preferences/tracking.js@@ -119,10 +119,6 @@ export default class extends Controller {(this.model.watched_tags?.length > 0 &&this.model.mutedCategories?.length > 0);- if (show && this.model.user_option.watched_precedence_over_muted === null) {- this.model.user_option.watched_precedence_over_muted =- this.siteSettings.watched_precedence_over_muted;- }return show;}diff --git a/lib/topic_query.rb b/lib/topic_query.rbindex 91dbc2327c8..ffe5c53d02e 100644--- a/lib/topic_query.rb+++ b/lib/topic_query.rb@@ -1012,7 +1012,7 @@ class TopicQueryif userwatched_tag_ids =- if user.watched_precedence_over_muted+ if user.user_option.watched_precedence_over_mutedTagUser.where(user: user).where("notification_level >= ?", TopicUser.notification_levels[:watching])@@ -1100,8 +1100,7 @@ class TopicQueryif user && !opts[:skip_categories]query_params[:regular] = CategoryUser.notification_levels[:regular]- query_params[:watching_or_infinite] = if user.watched_precedence_over_muted ||- SiteSetting.watched_precedence_over_muted+ query_params[:watching_or_infinite] = if user.user_option.watched_precedence_over_mutedCategoryUser.notification_levels[:watching]else99diff --git a/spec/lib/topic_query_spec.rb b/spec/lib/topic_query_spec.rbindex 593a9aa25bc..f901d80b77a 100644--- a/spec/lib/topic_query_spec.rb+++ b/spec/lib/topic_query_spec.rb@@ -2354,7 +2354,7 @@ RSpec.describe TopicQuery docontext "when enabled" doit "returns topics even if category or tag is muted but another tag or category is watched" do- SiteSetting.watched_precedence_over_muted = true+ user.user_option.update!(watched_precedence_over_muted: true)query = TopicQuery.new(user).list_latestexpect(query.topics.map(&:id)).to contain_exactly(topic.id,@@ -2366,24 +2366,11 @@ RSpec.describe TopicQuery docontext "when disabled" doit "returns topics without muted category or tag" do- SiteSetting.watched_precedence_over_muted = false+ user.user_option.update!(watched_precedence_over_muted: false)query = TopicQuery.new(user).list_latestexpect(query.topics.map(&:id)).to contain_exactly(topic.id)endend-- context "when disabled but overridden by user" do- it "returns topics even if category or tag is muted but another tag or category is watched" do- SiteSetting.watched_precedence_over_muted = false- user.user_option.update!(watched_precedence_over_muted: true)- query = TopicQuery.new(user).list_latest- expect(query.topics.map(&:id)).to contain_exactly(- topic.id,- topic_in_watched_category_and_muted_tag.id,- topic_in_muted_category_and_watched_tag.id,- )- end- endenddescribe "state parameter" dodiff --git a/spec/models/tag_user_spec.rb b/spec/models/tag_user_spec.rbindex b7ac3cf1779..d12edbd7394 100644--- a/spec/models/tag_user_spec.rb+++ b/spec/models/tag_user_spec.rb@@ -230,7 +230,7 @@ RSpec.describe TagUser doendit "sets notification level to the highest one if there are multiple tags" do- SiteSetting.watched_precedence_over_muted = true+ user.user_option.update!(watched_precedence_over_muted: true)TagUser.create!(user: user,diff --git a/spec/models/user_option_spec.rb b/spec/models/user_option_spec.rbindex c9ff9bd5cf5..b6f8c84138b 100644--- a/spec/models/user_option_spec.rb+++ b/spec/models/user_option_spec.rb@@ -86,6 +86,7 @@ RSpec.describe UserOption doSiteSetting.default_other_external_links_in_new_tab = trueSiteSetting.default_other_dynamic_favicon = trueSiteSetting.default_other_skip_new_user_tips = true+ SiteSetting.default_watched_precedence_over_muted = trueuser = Fabricate(:user)@@ -96,6 +97,7 @@ RSpec.describe UserOption doexpect(user.user_option.external_links_in_new_tab).to eq(true)expect(user.user_option.dynamic_favicon).to eq(true)expect(user.user_option.skip_new_user_tips).to eq(true)+ expect(user.user_option.watched_precedence_over_muted).to eq(true)endenddiff --git a/spec/requests/api/schemas/json/user_get_response.json b/spec/requests/api/schemas/json/user_get_response.jsonindex 8bbf5af43c2..122980ec31a 100644--- a/spec/requests/api/schemas/json/user_get_response.json+++ b/spec/requests/api/schemas/json/user_get_response.json@@ -814,7 +814,7 @@"type": "boolean"},"watched_precedence_over_muted": {- "type": ["boolean", "null"]+ "type": ["boolean"]},"seen_popups": {"type": ["array", "null"]diff --git a/spec/services/post_alerter_spec.rb b/spec/services/post_alerter_spec.rbindex c07ceaa1282..ebad9932d43 100644--- a/spec/services/post_alerter_spec.rb+++ b/spec/services/post_alerter_spec.rb@@ -2095,8 +2095,8 @@ RSpec.describe PostAlerter do)end- it "adds notification when watched_precedence_over_muted setting is true" do- SiteSetting.watched_precedence_over_muted = true+ it "adds notification when watched_precedence_over_muted preference is true" do+ user.user_option.update!(watched_precedence_over_muted: true)expect {PostAlerter.post_created(topic_with_muted_tag_and_watched_category.posts.first)}.to change { Notification.count }.by(1)@@ -2108,8 +2108,7 @@ RSpec.describe PostAlerter do}.by(1)end- it "respects user option even if watched_precedence_over_muted site setting is true" do- SiteSetting.watched_precedence_over_muted = true+ it "does not add notifcation when watched_precedence_over_muted preference is false" douser.user_option.update!(watched_precedence_over_muted: false)expect {PostAlerter.post_created(topic_with_muted_tag_and_watched_category.posts.first)@@ -2121,36 +2120,6 @@ RSpec.describe PostAlerter doNotification.count}.by(1)end-- it "does not add notification when watched_precedence_over_muted setting is false" do- SiteSetting.watched_precedence_over_muted = false- expect {- PostAlerter.post_created(topic_with_muted_tag_and_watched_category.posts.first)- }.not_to change { Notification.count }- expect {- PostAlerter.post_created(topic_with_muted_category_and_watched_tag.posts.first)- }.not_to change { Notification.count }- expect { PostAlerter.post_created(topic_with_watched_category.posts.first) }.to change {- Notification.count- }.by(1)- expect { PostAlerter.post_created(directly_watched_topic.posts.first) }.to change {- Notification.count- }.by(1)- end-- it "respects user option even if watched_precedence_over_muted site setting is false" do- SiteSetting.watched_precedence_over_muted = false- user.user_option.update!(watched_precedence_over_muted: true)- expect {- PostAlerter.post_created(topic_with_muted_tag_and_watched_category.posts.first)- }.to change { Notification.count }.by(1)- expect {- PostAlerter.post_created(topic_with_muted_category_and_watched_tag.posts.first)- }.to change { Notification.count }.by(1)- expect { PostAlerter.post_created(directly_watched_topic.posts.first) }.to change {- Notification.count- }.by(1)- endendcontext "with on change" do