FIX: topic_tracking_state when mute_all_categories_by_default is enabled

This commit is contained in:
David Taylor 2020-01-06 18:22:42 +00:00
parent ba00d87a16
commit d1779346e8
3 changed files with 25 additions and 6 deletions

View File

@ -306,9 +306,10 @@ class TopicTrackingState
#{tags_filter}
topics.deleted_at IS NULL AND
#{category_filter}
(category_users.notification_level IS NULL OR
last_read_post_number IS NOT NULL OR
category_users.notification_level <> #{CategoryUser.notification_levels[:muted]})
NOT (
last_read_post_number IS NULL AND
COALESCE(category_users.notification_level, #{CategoryUser.default_notification_level}) = #{CategoryUser.notification_levels[:muted]}
)
SQL
if opts[:topic_id]

View File

@ -857,8 +857,6 @@ class TopicQuery
category_id = get_category_id(opts[:exclude]) if opts
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}")
@ -866,7 +864,7 @@ class TopicQuery
OR COALESCE(category_users.notification_level, :default) <> :muted
OR tu.notification_level > :regular",
category_id: category_id || -1,
default: default_notification_level,
default: CategoryUser.default_notification_level,
muted: CategoryUser.notification_levels[:muted],
regular: TopicUser.notification_levels[:regular])
elsif SiteSetting.mute_all_categories_by_default

View File

@ -366,6 +366,26 @@ describe TopicTrackingState do
expect(report.length).to eq(1)
end
it "works when categories are default muted" do
SiteSetting.mute_all_categories_by_default = true
user = Fabricate(:user)
post
report = TopicTrackingState.report(user)
expect(report.length).to eq(0)
CategoryUser.create!(user_id: user.id,
notification_level: CategoryUser.notification_levels[:regular],
category_id: post.topic.category_id
)
create_post(topic_id: post.topic_id)
report = TopicTrackingState.report(user)
expect(report.length).to eq(1)
end
context 'muted tags' do
it "remove_muted_tags_from_latest is set to always" do
SiteSetting.remove_muted_tags_from_latest = 'always'