mirror of
https://github.com/discourse/discourse.git
synced 2025-06-03 18:53:53 +08:00
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:
@ -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 (
|
||||
|
Reference in New Issue
Block a user