mirror of
https://github.com/discourse/discourse-chat-integration.git
synced 2025-07-04 05:02:11 +00:00
FEATURE: Trigger follow rules when category changes (#164)
This commit is contained in:
parent
9f0303da58
commit
9332d77483
@ -15,9 +15,12 @@ module DiscourseChatIntegration
|
|||||||
# Abort if the post is blank
|
# Abort if the post is blank
|
||||||
return if post.blank?
|
return if post.blank?
|
||||||
|
|
||||||
# Abort if post is not either regular, or a 'tags_changed' small action
|
# Abort if post is not either regular, or a 'tags_changed'/'category_changed' small action
|
||||||
if (post.post_type != Post.types[:regular]) &&
|
if (post.post_type != Post.types[:regular]) &&
|
||||||
!(post.post_type == Post.types[:small_action] && post.action_code == "tags_changed")
|
!(
|
||||||
|
post.post_type == Post.types[:small_action] &&
|
||||||
|
%w[tags_changed category_changed].include?(post.action_code)
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -104,9 +107,16 @@ module DiscourseChatIntegration
|
|||||||
# If a matching rule is set to mute, we can discard it now
|
# If a matching rule is set to mute, we can discard it now
|
||||||
matching_rules = matching_rules.select { |rule| rule.filter != "mute" }
|
matching_rules = matching_rules.select { |rule| rule.filter != "mute" }
|
||||||
|
|
||||||
# If this is not the first post, discard all "follow" rules
|
# If this is not the first post, discard all "follow" rules. Unless it's a
|
||||||
|
# category_changed action post. If category changed, filter out and rules
|
||||||
|
# that aren't specific to a category
|
||||||
if !post.is_first_post?
|
if !post.is_first_post?
|
||||||
matching_rules = matching_rules.select { |rule| rule.filter != "follow" }
|
matching_rules =
|
||||||
|
if post.action_code == "category_changed"
|
||||||
|
matching_rules.select { |rule| rule.category_id.present? }
|
||||||
|
else
|
||||||
|
matching_rules.select { |rule| rule.filter != "follow" }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# All remaining rules now require a notification to be sent
|
# All remaining rules now require a notification to be sent
|
||||||
|
@ -316,6 +316,38 @@ RSpec.describe DiscourseChatIntegration::Manager do
|
|||||||
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
|
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "With `create_post_for_category_and_tag_changes` enabled" do
|
||||||
|
before(:each) { SiteSetting.create_post_for_category_and_tag_changes = true }
|
||||||
|
|
||||||
|
let(:admin) { Fabricate(:admin) }
|
||||||
|
let(:other_topic) { Fabricate(:topic) }
|
||||||
|
let(:other_topic_post) { Fabricate(:post, topic: topic) }
|
||||||
|
|
||||||
|
it "should trigger follow rules for specific categories when topic category changes" do
|
||||||
|
DiscourseChatIntegration::Rule.create!(
|
||||||
|
channel: chan1,
|
||||||
|
filter: "follow",
|
||||||
|
category_id: category.id,
|
||||||
|
)
|
||||||
|
|
||||||
|
PostRevisor.new(other_topic_post).revise!(admin, category_id: category.id)
|
||||||
|
|
||||||
|
manager.trigger_notifications(topic.ordered_posts.last.id)
|
||||||
|
|
||||||
|
expect(provider.sent_to_channel_ids).to contain_exactly(chan1.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "shouldn't trigger follow rules with wildcard category match" do
|
||||||
|
DiscourseChatIntegration::Rule.create!(channel: chan1, filter: "follow", category_id: nil)
|
||||||
|
|
||||||
|
PostRevisor.new(other_topic_post).revise!(admin, category_id: category.id)
|
||||||
|
|
||||||
|
manager.trigger_notifications(topic.ordered_posts.last.id)
|
||||||
|
|
||||||
|
expect(provider.sent_to_channel_ids).to contain_exactly
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "with tags enabled" do
|
describe "with tags enabled" do
|
||||||
let(:tag) { Fabricate(:tag, name: "gsoc") }
|
let(:tag) { Fabricate(:tag, name: "gsoc") }
|
||||||
let(:tagged_topic) { Fabricate(:topic, category_id: category.id, tags: [tag]) }
|
let(:tagged_topic) { Fabricate(:topic, category_id: category.id, tags: [tag]) }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user