mirror of
https://github.com/discourse/discourse.git
synced 2025-03-28 17:47:55 +08:00
FEATURE: Mute topics tagged with both muted and unmuted tags.
This commit is contained in:
parent
8858dbb5b8
commit
8728850452
@ -2015,7 +2015,8 @@ en:
|
|||||||
allow_staff_to_tag_pms: "Allow staff members to tag any personal message"
|
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"
|
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"
|
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."
|
force_lowercase_tags: "Force all new tags to be entirely lowercase."
|
||||||
|
|
||||||
company_name: "Company Name"
|
company_name: "Company Name"
|
||||||
|
@ -2059,6 +2059,8 @@ tags:
|
|||||||
client: true
|
client: true
|
||||||
remove_muted_tags_from_latest:
|
remove_muted_tags_from_latest:
|
||||||
default: false
|
default: false
|
||||||
|
mute_other_present_tags:
|
||||||
|
default: true
|
||||||
force_lowercase_tags:
|
force_lowercase_tags:
|
||||||
default: true
|
default: true
|
||||||
client: true
|
client: true
|
||||||
|
@ -876,31 +876,41 @@ class TopicQuery
|
|||||||
end
|
end
|
||||||
def remove_muted_tags(list, user, opts = nil)
|
def remove_muted_tags(list, user, opts = nil)
|
||||||
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
|
return list
|
||||||
else
|
end
|
||||||
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
|
|
||||||
|
|
||||||
if TagUser.lookup(user, :muted).joins(:tag).where('tags.name = ?', showing_tag).exists?
|
muted_tag_ids = TagUser.lookup(user, :muted).pluck(:tag_id)
|
||||||
list # if viewing the topic list for a muted tag, show all the topics
|
if muted_tag_ids.blank?
|
||||||
else
|
return list
|
||||||
muted_tag_ids = TagUser.lookup(user, :muted).pluck(:tag_id)
|
end
|
||||||
list = list.where("
|
|
||||||
EXISTS (
|
showing_tag = if opts[:filter]
|
||||||
SELECT 1
|
f = opts[:filter].split('/')
|
||||||
FROM topic_tags tt
|
f[0] == 'tags' ? f[1] : nil
|
||||||
WHERE tt.tag_id NOT IN (:tag_ids)
|
else
|
||||||
AND tt.topic_id = topics.id
|
nil
|
||||||
) OR NOT EXISTS (SELECT 1 FROM topic_tags tt WHERE tt.topic_id = topics.id)", tag_ids: muted_tag_ids)
|
end
|
||||||
end
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -250,6 +250,7 @@ describe TopicQuery do
|
|||||||
|
|
||||||
muted_topic = Fabricate(:topic, tags: [muted_tag])
|
muted_topic = Fabricate(:topic, tags: [muted_tag])
|
||||||
tagged_topic = Fabricate(:topic, tags: [other_tag])
|
tagged_topic = Fabricate(:topic, tags: [other_tag])
|
||||||
|
muted_tagged_topic = Fabricate(:topic, tags: [muted_tag, other_tag])
|
||||||
untagged_topic = Fabricate(:topic)
|
untagged_topic = Fabricate(:topic)
|
||||||
|
|
||||||
TagUser.create!(user_id: user.id,
|
TagUser.create!(user_id: user.id,
|
||||||
@ -257,12 +258,18 @@ describe TopicQuery do
|
|||||||
notification_level: CategoryUser.notification_levels[:muted])
|
notification_level: CategoryUser.notification_levels[:muted])
|
||||||
|
|
||||||
topic_ids = topic_query.list_latest.topics.map(&:id)
|
topic_ids = topic_query.list_latest.topics.map(&:id)
|
||||||
|
|
||||||
expect(topic_ids).to contain_exactly(tagged_topic.id, untagged_topic.id)
|
expect(topic_ids).to contain_exactly(tagged_topic.id, untagged_topic.id)
|
||||||
|
|
||||||
topic_ids = topic_query.list_new.topics.map(&:id)
|
topic_ids = topic_query.list_new.topics.map(&:id)
|
||||||
|
|
||||||
expect(topic_ids).to contain_exactly(tagged_topic.id, untagged_topic.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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user