mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: minor refactoring to reduce the code duplication.
This commit is contained in:
parent
57bbcf4c5d
commit
f83125f0c2
@ -864,37 +864,28 @@ class TopicQuery
|
|||||||
def remove_muted_categories(list, user, opts = nil)
|
def remove_muted_categories(list, user, opts = nil)
|
||||||
category_id = get_category_id(opts[:exclude]) if opts
|
category_id = get_category_id(opts[:exclude]) if opts
|
||||||
|
|
||||||
if SiteSetting.mute_all_categories_by_default
|
if user
|
||||||
if user
|
default_notification_level = SiteSetting.mute_all_categories_by_default ? CategoryUser.notification_levels[:muted] : CategoryUser.notification_levels[:regular]
|
||||||
list = list
|
|
||||||
.references("cu")
|
|
||||||
.joins("LEFT JOIN category_users ON category_users.category_id = topics.category_id AND category_users.user_id = #{user.id}")
|
|
||||||
.where("topics.category_id = :category_id
|
|
||||||
OR COALESCE(category_users.notification_level, :muted) <> :muted
|
|
||||||
OR tu.notification_level > :regular",
|
|
||||||
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
|
list = list
|
||||||
.references("cu")
|
.references("cu")
|
||||||
.joins("LEFT JOIN category_users ON category_users.category_id = topics.category_id AND category_users.user_id = #{user.id}")
|
.joins("LEFT JOIN category_users ON category_users.category_id = topics.category_id AND category_users.user_id = #{user.id}")
|
||||||
.where("COALESCE(category_users.notification_level, :regular) <> :muted
|
.where("topics.category_id = :category_id
|
||||||
OR category_users.category_id = :category_id OR tu.notification_level >= :tracking",
|
OR COALESCE(category_users.notification_level, :default) <> :muted
|
||||||
muted: CategoryUser.notification_levels[:muted],
|
OR tu.notification_level > :regular",
|
||||||
regular: CategoryUser.notification_levels[:regular],
|
category_id: category_id || -1,
|
||||||
tracking: TopicUser.notification_levels[:tracking],
|
default: default_notification_level,
|
||||||
category_id: category_id || -1)
|
muted: CategoryUser.notification_levels[:muted],
|
||||||
|
regular: TopicUser.notification_levels[:regular])
|
||||||
|
elsif SiteSetting.mute_all_categories_by_default
|
||||||
|
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?
|
||||||
else
|
else
|
||||||
category_ids = SiteSetting.default_categories_muted.split("|").map(&:to_i)
|
category_ids = SiteSetting.default_categories_muted.split("|").map(&:to_i)
|
||||||
category_ids -= [category_id] if category_id.present? && category_ids.include?(category_id)
|
category_ids -= [category_id] if category_id.present? && category_ids.include?(category_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user