FEATURE: Mute topics tagged with both muted and unmuted tags.

This commit is contained in:
Dan Ungureanu 2019-05-27 19:44:24 +03:00 committed by Guo Xiang Tan
parent 8858dbb5b8
commit 8728850452
4 changed files with 47 additions and 27 deletions

View File

@ -2015,7 +2015,8 @@ en:
allow_staff_to_tag_pms: "Allow staff members to tag any personal message"
min_trust_level_to_tag_topics: "Minimum trust level required to tag topics"
suppress_overlapping_tags_in_list: "If tags match exact words in topic titles, don't show the tag"
remove_muted_tags_from_latest: "Don't show topics tagged with muted tags in the latest topic list."
remove_muted_tags_from_latest: "Don't show topics tagged only with muted tags in the latest topic list."
mute_other_present_tags: "Don't show topics tagged with both muted and unmuted tags in the latest topic list."
force_lowercase_tags: "Force all new tags to be entirely lowercase."
company_name: "Company Name"

View File

@ -2059,6 +2059,8 @@ tags:
client: true
remove_muted_tags_from_latest:
default: false
mute_other_present_tags:
default: true
force_lowercase_tags:
default: true
client: true

View File

@ -876,31 +876,41 @@ class TopicQuery
end
def remove_muted_tags(list, user, opts = nil)
if user.nil? || !SiteSetting.tagging_enabled || !SiteSetting.remove_muted_tags_from_latest
list
else
if !TagUser.lookup(user, :muted).exists?
list
else
showing_tag = if opts[:filter]
f = opts[:filter].split('/')
f[0] == 'tags' ? f[1] : nil
else
nil
end
return list
end
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
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
muted_tag_ids = TagUser.lookup(user, :muted).pluck(:tag_id)
if muted_tag_ids.blank?
return list
end
showing_tag = if opts[:filter]
f = opts[:filter].split('/')
f[0] == 'tags' ? f[1] : nil
else
nil
end
# if viewing the topic list for a muted tag, show all the topics
if showing_tag.present? && TagUser.lookup(user, :muted).joins(:tag).where('tags.name = ?', showing_tag).exists?
return list
end
if SiteSetting.mute_other_present_tags
list = list.where("
NOT EXISTS(
SELECT 1
FROM topic_tags tt
WHERE tt.tag_id IN (:tag_ids)
AND tt.topic_id = topics.id)", tag_ids: muted_tag_ids)
else
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

View File

@ -250,6 +250,7 @@ describe TopicQuery do
muted_topic = Fabricate(:topic, tags: [muted_tag])
tagged_topic = Fabricate(:topic, tags: [other_tag])
muted_tagged_topic = Fabricate(:topic, tags: [muted_tag, other_tag])
untagged_topic = Fabricate(:topic)
TagUser.create!(user_id: user.id,
@ -257,12 +258,18 @@ describe TopicQuery do
notification_level: CategoryUser.notification_levels[:muted])
topic_ids = topic_query.list_latest.topics.map(&:id)
expect(topic_ids).to contain_exactly(tagged_topic.id, untagged_topic.id)
topic_ids = topic_query.list_new.topics.map(&:id)
expect(topic_ids).to contain_exactly(tagged_topic.id, untagged_topic.id)
SiteSetting.mute_other_present_tags = false
topic_ids = topic_query.list_latest.topics.map(&:id)
expect(topic_ids).to contain_exactly(muted_tagged_topic.id, tagged_topic.id, untagged_topic.id)
topic_ids = topic_query.list_new.topics.map(&:id)
expect(topic_ids).to contain_exactly(muted_tagged_topic.id, tagged_topic.id, untagged_topic.id)
end
end