diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 1ba8be9a4b1..eb72e7678b7 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -188,7 +188,7 @@ class PostAction < ActiveRecord::Base return if staff_already_replied?(related_post.topic) message_key = "flags_dispositions.#{disposition}" message_key << "_and_deleted" if delete_post - related_post.topic.add_moderator_post(moderator, I18n.t(message_key), skip_notifications: true) + related_post.topic.add_moderator_post(moderator, I18n.t(message_key)) end def staff_already_replied?(topic) diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index eaf1df3ee38..9064177433c 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -10,14 +10,14 @@ class PostAlerter def after_create_post(post) if post.topic.private_message? # If it's a private message, notify the topic_allowed_users - post.topic.all_allowed_users.reject{ |user| user.id == post.user_id }.each do |user| - next if user.blank? - + post.topic.all_allowed_users.reject do |user| + user.blank? || + user.id == Discourse::SYSTEM_USER_ID || + user.id == post.user_id + end.each do |user| if TopicUser.get(post.topic, user).try(:notification_level) == TopicUser.notification_levels[:tracking] - next unless post.reply_to_post_number - next unless post.reply_to_post.user_id == user.id + next unless post.reply_to_post_number || post.reply_to_post.user_id == user.id end - create_notification(user, Notification.types[:private_message], post) end elsif post.post_type != Post.types[:moderator_action] @@ -82,6 +82,7 @@ class PostAlerter def create_notification(user, type, post, opts={}) return if user.blank? + return if user.id == Discourse::SYSTEM_USER_ID # Make sure the user can see the post return unless Guardian.new(user).can_see?(post) diff --git a/lib/post_creator.rb b/lib/post_creator.rb index fb001810c7a..d4627ca2ee7 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -97,7 +97,7 @@ class PostCreator if @post && @post.errors.empty? publish - PostAlerter.post_created(@post) unless @opts[:import_mode] || @opts[:skip_notifications] + PostAlerter.post_created(@post) unless @opts[:import_mode] track_latest_on_category enqueue_jobs diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index 49df9db989e..bb364def59e 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -507,15 +507,6 @@ describe PostAction do expect(topic.posts.count).to eq(1) end - 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