diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 6b9704d54..c1d75d551 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -187,7 +187,7 @@ class PostAction < ActiveRecord::Base return if moderator_already_replied?(related_post.topic, moderator) message_key = "flags_dispositions.#{disposition}" message_key << "_and_deleted" if delete_post - related_post.topic.add_moderator_post(moderator, I18n.t(message_key)) + related_post.topic.add_moderator_post(moderator, I18n.t(message_key), skip_notifications: true) end def moderator_already_replied?(topic, moderator) diff --git a/app/models/topic.rb b/app/models/topic.rb index 4bd6180d5..03868e13b 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -488,6 +488,7 @@ class Topic < ActiveRecord::Base raw: text, post_type: Post.types[:moderator_action], no_bump: opts[:bump].blank?, + skip_notifications: opts[:skip_notifications], topic_id: self.id) new_post = creator.create increment!(:moderator_posts_count) diff --git a/lib/post_creator.rb b/lib/post_creator.rb index d87aa172e..3c1d60279 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -96,7 +96,7 @@ class PostCreator if @post && @post.errors.empty? publish - PostAlerter.post_created(@post) unless @opts[:import_mode] + PostAlerter.post_created(@post) unless @opts[:import_mode] || @opts[:skip_notifications] track_latest_on_category enqueue_jobs diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index b6fb5e836..6e4645dc2 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -28,7 +28,7 @@ describe PostAction do mod = moderator Group.refresh_automatic_groups! - action = PostAction.act(codinghorror, post, PostActionType.types[:notify_moderators], message: "this is my special long message"); + action = PostAction.act(codinghorror, post, PostActionType.types[:notify_moderators], message: "this is my special long message") posts = Post.joins(:topic) .select('posts.id, topics.subtype, posts.topic_id') @@ -76,7 +76,7 @@ describe PostAction do it "creates a pm if selected" do post = build(:post, id: 1000) PostCreator.any_instance.expects(:create).returns(post) - PostAction.act(build(:user), build(:post), PostActionType.types[:notify_moderators], message: "this is my special message"); + PostAction.act(build(:user), build(:post), PostActionType.types[:notify_moderators], message: "this is my special message") end end @@ -89,7 +89,7 @@ describe PostAction do it "sends an email to user if selected" do PostCreator.any_instance.expects(:create).returns(build(:post)) - PostAction.act(build(:user), post, PostActionType.types[:notify_user], message: "this is my special message"); + PostAction.act(build(:user), post, PostActionType.types[:notify_user], message: "this is my special message") end end end @@ -458,4 +458,18 @@ describe PostAction do end + describe ".add_moderator_post_if_needed" do + + it "should not generate a notification for auto-message" do + post = create_post + + PostAction.act(moderator, post, PostActionType.types[:spam], message: "WAT") + + PostAlerter.expects(:post_created).never + + PostAction.agree_flags!(post, admin) + end + + end + end