mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
FIX: muted tags showing in latest topic list
This commit is contained in:
parent
6827239444
commit
f10c4682cd
3 changed files with 38 additions and 18 deletions
|
@ -185,14 +185,8 @@ module DiscourseTagging
|
||||||
end
|
end
|
||||||
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)
|
def self.muted_tags(user)
|
||||||
return [] unless 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
|
||||||
end
|
end
|
||||||
|
|
|
@ -597,8 +597,7 @@ class TopicQuery
|
||||||
if user.nil? || !SiteSetting.tagging_enabled || !SiteSetting.remove_muted_tags_from_latest
|
if user.nil? || !SiteSetting.tagging_enabled || !SiteSetting.remove_muted_tags_from_latest
|
||||||
list
|
list
|
||||||
else
|
else
|
||||||
muted_tags = DiscourseTagging.muted_tags(user)
|
if !TagUser.lookup(user, :muted).exists?
|
||||||
if muted_tags.empty?
|
|
||||||
list
|
list
|
||||||
else
|
else
|
||||||
showing_tag = if opts[:filter]
|
showing_tag = if opts[:filter]
|
||||||
|
@ -608,17 +607,17 @@ class TopicQuery
|
||||||
nil
|
nil
|
||||||
end
|
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
|
list # if viewing the topic list for a muted tag, show all the topics
|
||||||
else
|
else
|
||||||
arr = muted_tags.map{ |z| "'#{z}'" }.join(',')
|
muted_tag_ids = TagUser.lookup(user, :muted).pluck(:tag_id)
|
||||||
list.where("EXISTS (
|
list = list.where("
|
||||||
SELECT 1
|
EXISTS (
|
||||||
FROM topic_custom_fields tcf
|
SELECT 1
|
||||||
WHERE tcf.name = 'tags'
|
FROM topic_tags tt
|
||||||
AND tcf.value NOT IN (#{arr})
|
WHERE tt.tag_id NOT IN (:tag_ids)
|
||||||
AND tcf.topic_id = topics.id
|
AND tt.topic_id = topics.id
|
||||||
) OR NOT EXISTS (select 1 from topic_custom_fields tcf where tcf.name = 'tags' and tcf.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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -178,6 +178,33 @@ describe TopicQuery do
|
||||||
end
|
end
|
||||||
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
|
context 'a bunch of topics' do
|
||||||
let!(:regular_topic) do
|
let!(:regular_topic) do
|
||||||
Fabricate(:topic, title: 'this is a regular topic',
|
Fabricate(:topic, title: 'this is a regular topic',
|
||||||
|
|
Loading…
Reference in a new issue