diff --git a/app/models/post_action.rb b/app/models/post_action.rb index e8a78aa63..8f41cd3c0 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -155,13 +155,19 @@ class PostAction < ActiveRecord::Base end def add_moderator_post_if_needed(moderator, disposition, delete_post=false) - return unless related_post - return if related_post.topic.posts.where(post_type: Post.types[:moderator_action]).exists? + return if related_post.nil? + 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)) end + def moderator_already_replied?(topic, moderator) + topic.posts + .where("user_id = :user_id OR post_type = :post_type", user_id: moderator.id, post_type: Post.types[:moderator_action]) + .exists? + end + def self.create_message_for_post_action(user, post, post_action_type_id, opts) post_action_type = PostActionType.types[post_action_type_id] diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index 11fe6676d..6fadf3a43 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -43,9 +43,7 @@ describe PostAction do topic.topic_users(true).map(&:notification_level).uniq.should == [TopicUser.notification_levels[:watching]] # reply to PM should not clear flag - p = PostCreator.new(mod, topic_id: posts[0].topic_id, raw: "This is my test reply to the user, it should clear flags") - p.create - + PostCreator.new(mod, topic_id: posts[0].topic_id, raw: "This is my test reply to the user, it should clear flags").create action.reload action.deleted_at.should be_nil