FIX: topic_tracking_state when mute_all_categories_by_default is enabled
This commit is contained in:
parent
ba00d87a16
commit
d1779346e8
|
@ -306,9 +306,10 @@ class TopicTrackingState
|
||||||
#{tags_filter}
|
#{tags_filter}
|
||||||
topics.deleted_at IS NULL AND
|
topics.deleted_at IS NULL AND
|
||||||
#{category_filter}
|
#{category_filter}
|
||||||
(category_users.notification_level IS NULL OR
|
NOT (
|
||||||
last_read_post_number IS NOT NULL OR
|
last_read_post_number IS NULL AND
|
||||||
category_users.notification_level <> #{CategoryUser.notification_levels[:muted]})
|
COALESCE(category_users.notification_level, #{CategoryUser.default_notification_level}) = #{CategoryUser.notification_levels[:muted]}
|
||||||
|
)
|
||||||
SQL
|
SQL
|
||||||
|
|
||||||
if opts[:topic_id]
|
if opts[:topic_id]
|
||||||
|
|
|
@ -857,8 +857,6 @@ class TopicQuery
|
||||||
category_id = get_category_id(opts[:exclude]) if opts
|
category_id = get_category_id(opts[:exclude]) if opts
|
||||||
|
|
||||||
if user
|
if user
|
||||||
default_notification_level = SiteSetting.mute_all_categories_by_default ? CategoryUser.notification_levels[:muted] : CategoryUser.notification_levels[:regular]
|
|
||||||
|
|
||||||
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}")
|
||||||
|
@ -866,7 +864,7 @@ class TopicQuery
|
||||||
OR COALESCE(category_users.notification_level, :default) <> :muted
|
OR COALESCE(category_users.notification_level, :default) <> :muted
|
||||||
OR tu.notification_level > :regular",
|
OR tu.notification_level > :regular",
|
||||||
category_id: category_id || -1,
|
category_id: category_id || -1,
|
||||||
default: default_notification_level,
|
default: CategoryUser.default_notification_level,
|
||||||
muted: CategoryUser.notification_levels[:muted],
|
muted: CategoryUser.notification_levels[:muted],
|
||||||
regular: TopicUser.notification_levels[:regular])
|
regular: TopicUser.notification_levels[:regular])
|
||||||
elsif SiteSetting.mute_all_categories_by_default
|
elsif SiteSetting.mute_all_categories_by_default
|
||||||
|
|
|
@ -366,6 +366,26 @@ describe TopicTrackingState do
|
||||||
expect(report.length).to eq(1)
|
expect(report.length).to eq(1)
|
||||||
end
|
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
|
context 'muted tags' do
|
||||||
it "remove_muted_tags_from_latest is set to always" do
|
it "remove_muted_tags_from_latest is set to always" do
|
||||||
SiteSetting.remove_muted_tags_from_latest = 'always'
|
SiteSetting.remove_muted_tags_from_latest = 'always'
|
||||||
|
|
Loading…
Reference in New Issue