From f6a8f6cfe5438f71a289f46a6cc0cb06fd4715ad Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 8 Jul 2013 12:44:55 +1000 Subject: [PATCH] don't notify on moderator actions, they just cause noise, also filter out pms properly while at it --- lib/post_creator.rb | 4 ++-- spec/components/post_creator_spec.rb | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 09852b105..9bbbd50f7 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -122,7 +122,7 @@ class PostCreator end def after_post_create - if @post.post_number > 1 + if !@topic.private_message? && @post.post_number > 1 && @post.post_type != Post.types[:moderator_action] TopicTrackingState.publish_unread(@post) end end @@ -132,7 +132,7 @@ class PostCreator # Don't publish invisible topics return unless @topic.visible? - return if @topic.private_message? + return if @topic.private_message? || @post.post_type == Post.types[:moderator_action] @topic.posters = @topic.posters_summary @topic.posts_count = 1 diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index 8dd8c0698..3289db853 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -10,18 +10,18 @@ describe PostCreator do let(:user) { Fabricate(:user) } - context 'new topic' do + context "new topic" do let(:category) { Fabricate(:category, user: user) } let(:topic) { Fabricate(:topic, user: user) } - let(:basic_topic_params) { {title: 'hello world topic', raw: 'my name is fred', archetype_id: 1} } - let(:image_sizes) { {'http://an.image.host/image.jpg' => {'width' => 111, 'height' => 222}} } + let(:basic_topic_params) { {title: "hello world topic", raw: "my name is fred", archetype_id: 1} } + let(:image_sizes) { {'http://an.image.host/image.jpg' => {"width" => 111, "height" => 222}} } let(:creator) { PostCreator.new(user, basic_topic_params) } let(:creator_with_category) { PostCreator.new(user, basic_topic_params.merge(category: category.name )) } - let(:creator_with_meta_data) { PostCreator.new(user, basic_topic_params.merge(meta_data: {hello: 'world'} )) } + let(:creator_with_meta_data) { PostCreator.new(user, basic_topic_params.merge(meta_data: {hello: "world"} )) } let(:creator_with_image_sizes) { PostCreator.new(user, basic_topic_params.merge(image_sizes: image_sizes)) } - it 'ensures the user can create the topic' do + it "ensures the user can create the topic" do Guardian.any_instance.expects(:can_create?).with(Topic,nil).returns(false) lambda { creator.create }.should raise_error(Discourse::InvalidAccess) end @@ -38,14 +38,26 @@ describe PostCreator do end - context 'success' do + context "success" do it "doesn't return true for spam" do creator.create creator.spam?.should be_false end - it 'generates the correct messages for a secure topic' do + it "does not notify on system messages" do + admin = Fabricate(:admin) + messages = MessageBus.track_publish do + p = PostCreator.create(admin, basic_topic_params.merge(post_type: Post.types[:moderator_action])) + PostCreator.create(admin, basic_topic_params.merge(topic_id: p.topic_id, post_type: Post.types[:moderator_action])) + end + # don't notify on system messages they introduce too much noise + channels = messages.map(&:channel) + channels.find{|s| s =~ /unread/}.should be_nil + channels.find{|s| s =~ /new/}.should be_nil + end + + it "generates the correct messages for a secure topic" do admin = Fabricate(:admin) @@ -59,7 +71,7 @@ describe PostCreator do messages = MessageBus.track_publish do created_post = PostCreator.new(admin, basic_topic_params.merge(category: cat.name)).create - reply = PostCreator.new(admin, raw: 'this is my test reply 123 testing', topic_id: created_post.topic_id).create + reply = PostCreator.new(admin, raw: "this is my test reply 123 testing", topic_id: created_post.topic_id).create end topic_id = created_post.topic_id