FEATURE: support to mute all categories by default. (#8295)

Instead of enabling `suppress_from_latest` setting on many categories now we can enable `mute_all_categories_by_default` site setting. Then users should opt-in to categories for them to appear in the latest and categories pages.
This commit is contained in:
Vinoth Kannan
2019-11-08 08:28:11 +05:30
committed by GitHub
parent deec2cf578
commit ba5b78a348
11 changed files with 147 additions and 26 deletions

View File

@ -869,7 +869,34 @@ class TopicQuery
def remove_muted_categories(list, user, opts = nil)
category_id = get_category_id(opts[:exclude]) if opts
if user
if SiteSetting.mute_all_categories_by_default
if user
list = list.references("cu")
.where("
NOT EXISTS (
SELECT 1
FROM categories c
LEFT OUTER JOIN category_users cu
ON c.id = cu.category_id AND cu.user_id = :user_id
WHERE c.id = topics.category_id
AND c.id <> :category_id
AND (COALESCE(cu.notification_level, :muted) = :muted)
AND (COALESCE(tu.notification_level, :regular) <= :regular)
)", user_id: user.id,
muted: CategoryUser.notification_levels[:muted],
regular: TopicUser.notification_levels[:regular],
category_id: category_id || -1)
else
category_ids = [
SiteSetting.default_categories_watching.split("|"),
SiteSetting.default_categories_tracking.split("|"),
SiteSetting.default_categories_watching_first_post.split("|")
].flatten.map(&:to_i)
category_ids << category_id if category_id.present? && category_ids.exclude?(category_id)
list = list.where("topics.category_id IN (?)", category_ids) if category_ids.present?
end
elsif user
list = list.references("cu")
.where("
NOT EXISTS (