FIX: muted tags showing in latest topic list
This commit is contained in:
parent
6827239444
commit
f10c4682cd
|
@ -185,14 +185,8 @@ module DiscourseTagging
|
|||
end
|
||||
end
|
||||
|
||||
# TODO: this is unused?
|
||||
def self.notification_key(tag_id)
|
||||
"tags_notification:#{tag_id}"
|
||||
end
|
||||
|
||||
# TODO: this is unused?
|
||||
def self.muted_tags(user)
|
||||
return [] unless user
|
||||
UserCustomField.where(user_id: user.id, value: TopicUser.notification_levels[:muted]).pluck(:name).map { |x| x[0,17] == "tags_notification" ? x[18..-1] : nil}.compact
|
||||
TagUser.lookup(user, :muted).joins(:tag).pluck('tags.name')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -597,8 +597,7 @@ class TopicQuery
|
|||
if user.nil? || !SiteSetting.tagging_enabled || !SiteSetting.remove_muted_tags_from_latest
|
||||
list
|
||||
else
|
||||
muted_tags = DiscourseTagging.muted_tags(user)
|
||||
if muted_tags.empty?
|
||||
if !TagUser.lookup(user, :muted).exists?
|
||||
list
|
||||
else
|
||||
showing_tag = if opts[:filter]
|
||||
|
@ -608,17 +607,17 @@ class TopicQuery
|
|||
nil
|
||||
end
|
||||
|
||||
if muted_tags.include?(showing_tag)
|
||||
if TagUser.lookup(user, :muted).joins(:tag).where('tags.name = ?', showing_tag).exists?
|
||||
list # if viewing the topic list for a muted tag, show all the topics
|
||||
else
|
||||
arr = muted_tags.map{ |z| "'#{z}'" }.join(',')
|
||||
list.where("EXISTS (
|
||||
SELECT 1
|
||||
FROM topic_custom_fields tcf
|
||||
WHERE tcf.name = 'tags'
|
||||
AND tcf.value NOT IN (#{arr})
|
||||
AND tcf.topic_id = topics.id
|
||||
) OR NOT EXISTS (select 1 from topic_custom_fields tcf where tcf.name = 'tags' and tcf.topic_id = topics.id)")
|
||||
muted_tag_ids = TagUser.lookup(user, :muted).pluck(:tag_id)
|
||||
list = list.where("
|
||||
EXISTS (
|
||||
SELECT 1
|
||||
FROM topic_tags tt
|
||||
WHERE tt.tag_id NOT IN (:tag_ids)
|
||||
AND tt.topic_id = topics.id
|
||||
) OR NOT EXISTS (SELECT 1 FROM topic_tags tt WHERE tt.topic_id = topics.id)", tag_ids: muted_tag_ids)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -178,6 +178,33 @@ describe TopicQuery do
|
|||
end
|
||||
end
|
||||
|
||||
context 'muted tags' do
|
||||
it 'is removed from new and latest lists' do
|
||||
SiteSetting.tagging_enabled = true
|
||||
SiteSetting.remove_muted_tags_from_latest = true
|
||||
|
||||
muted_tag, other_tag = Fabricate(:tag), Fabricate(:tag)
|
||||
|
||||
muted_topic = Fabricate(:topic, tags: [muted_tag])
|
||||
tagged_topic = Fabricate(:topic, tags: [other_tag])
|
||||
untagged_topic = Fabricate(:topic)
|
||||
|
||||
TagUser.create!(user_id: user.id,
|
||||
tag_id: muted_tag.id,
|
||||
notification_level: CategoryUser.notification_levels[:muted])
|
||||
|
||||
topic_ids = topic_query.list_latest.topics.map(&:id)
|
||||
expect(topic_ids).not_to include(muted_topic.id)
|
||||
expect(topic_ids).to include(tagged_topic.id)
|
||||
expect(topic_ids).to include(untagged_topic.id)
|
||||
|
||||
topic_ids = topic_query.list_new.topics.map(&:id)
|
||||
expect(topic_ids).not_to include(muted_topic.id)
|
||||
expect(topic_ids).to include(tagged_topic.id)
|
||||
expect(topic_ids).to include(untagged_topic.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'a bunch of topics' do
|
||||
let!(:regular_topic) do
|
||||
Fabricate(:topic, title: 'this is a regular topic',
|
||||
|
|
Loading…
Reference in New Issue