diff --git a/plugin.rb b/plugin.rb index c8a466e..0f76787 100644 --- a/plugin.rb +++ b/plugin.rb @@ -103,6 +103,8 @@ after_initialize do triggerables %i[topic_tags_changed] script do |context, fields, automation| + next if context["topic"].private_message? + # DiscourseTagging.tag_topic_by_names runs on topic creation and on tags change # we only want to send a message when tags change next if context["topic"].new_record? diff --git a/spec/integration/automation_spec.rb b/spec/integration/automation_spec.rb index 081de47..788a8be 100644 --- a/spec/integration/automation_spec.rb +++ b/spec/integration/automation_spec.rb @@ -29,6 +29,8 @@ RSpec.describe "Triggering notifications" do SiteSetting.create_tag_allowed_groups = Group::AUTO_GROUPS[:everyone] SiteSetting.tag_topic_allowed_groups = Group::AUTO_GROUPS[:everyone] + SiteSetting.pm_tags_allowed_for_groups = Group::AUTO_GROUPS[:everyone] + automation.upsert_field!( "watching_categories", "categories", @@ -84,5 +86,24 @@ RSpec.describe "Triggering notifications" do ) expect(validated_provider.sent_messages.length).to eq(0) end + + it "should not trigger notifications for PMs" do + automation.upsert_field!( + "watching_categories", + "categories", + { "value" => [nil] }, + target: "trigger", + ) + + topic = + TopicCreator.create( + admin, + Guardian.new(admin), + valid_attrs.merge(archetype: Archetype.private_message, target_usernames: admin.username), + ) + + DiscourseTagging.tag_topic_by_names(topic, Guardian.new(admin), [tag.name]) + expect(validated_provider.sent_messages.length).to eq(0) + end end end