mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 02:11:08 -06:00
FIX: muted tags removed topics with no tags from counts
We previously did not account for completely untagged topics when looking at muted tags, this caused new/unread counts to be off if 1. You had muted tags 2. You had an unread/new topic 3. This topic had no tags
This commit is contained in:
parent
136835370c
commit
2acec4370b
@ -315,18 +315,26 @@ class TopicTrackingState
|
|||||||
"(topics.visible #{append}) AND"
|
"(topics.visible #{append}) AND"
|
||||||
end
|
end
|
||||||
|
|
||||||
tags_filter =
|
tags_filter = ""
|
||||||
if opts[:muted_tag_ids].present? && SiteSetting.remove_muted_tags_from_latest == 'always'
|
|
||||||
<<~SQL
|
if (muted_tag_ids = opts[:muted_tag_ids]).present? && ['always', 'only_muted'].include?(SiteSetting.remove_muted_tags_from_latest)
|
||||||
NOT ((select array_agg(tag_id) from topic_tags where topic_tags.topic_id = topics.id) && ARRAY[#{opts[:muted_tag_ids].join(',')}]) AND
|
existing_tags_sql = "(select array_agg(tag_id) from topic_tags where topic_tags.topic_id = topics.id)"
|
||||||
|
muted_tags_array_sql = "ARRAY[#{opts[:muted_tag_ids].join(',')}]"
|
||||||
|
|
||||||
|
if SiteSetting.remove_muted_tags_from_latest == 'always'
|
||||||
|
tags_filter = <<~SQL
|
||||||
|
NOT (
|
||||||
|
COALESCE(#{existing_tags_sql}, ARRAY[]::int[]) && #{muted_tags_array_sql}
|
||||||
|
) AND
|
||||||
SQL
|
SQL
|
||||||
elsif opts[:muted_tag_ids].present? && SiteSetting.remove_muted_tags_from_latest == 'only_muted'
|
else # only muted
|
||||||
<<~SQL
|
tags_filter = <<~SQL
|
||||||
NOT ((select array_agg(tag_id) from topic_tags where topic_tags.topic_id = topics.id) <@ ARRAY[#{opts[:muted_tag_ids].join(',')}]) AND
|
NOT (
|
||||||
|
COALESCE(#{existing_tags_sql}, ARRAY[-999]) <@ #{muted_tags_array_sql}
|
||||||
|
) AND
|
||||||
SQL
|
SQL
|
||||||
else
|
|
||||||
""
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
sql = +<<~SQL
|
sql = +<<~SQL
|
||||||
SELECT #{select}
|
SELECT #{select}
|
||||||
|
@ -446,6 +446,11 @@ describe TopicTrackingState do
|
|||||||
|
|
||||||
report = TopicTrackingState.report(user)
|
report = TopicTrackingState.report(user)
|
||||||
expect(report.length).to eq(0)
|
expect(report.length).to eq(0)
|
||||||
|
|
||||||
|
TopicTag.where(topic_id: topic.id).delete_all
|
||||||
|
|
||||||
|
report = TopicTrackingState.report(user)
|
||||||
|
expect(report.length).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "remove_muted_tags_from_latest is set to only_muted" do
|
it "remove_muted_tags_from_latest is set to only_muted" do
|
||||||
@ -475,6 +480,11 @@ describe TopicTrackingState do
|
|||||||
|
|
||||||
report = TopicTrackingState.report(user)
|
report = TopicTrackingState.report(user)
|
||||||
expect(report.length).to eq(0)
|
expect(report.length).to eq(0)
|
||||||
|
|
||||||
|
TopicTag.where(topic_id: topic.id).delete_all
|
||||||
|
|
||||||
|
report = TopicTrackingState.report(user)
|
||||||
|
expect(report.length).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "remove_muted_tags_from_latest is set to never" do
|
it "remove_muted_tags_from_latest is set to never" do
|
||||||
|
Loading…
Reference in New Issue
Block a user