diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 766d072ab..ac3f68779 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -124,6 +124,11 @@ class PostAction < ActiveRecord::Base end end + def remove_act!(user) + trash! + run_callbacks(:save) + end + def is_bookmark? post_action_type_id == PostActionType.types[:bookmark] end diff --git a/lib/post_creator.rb b/lib/post_creator.rb index e1835ce0f..c48073f59 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -105,6 +105,8 @@ class PostCreator topic.allowed_users.where(["users.email_private_messages = true and users.id != ?", @user.id]).each do |u| Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes, :user_email, type: :private_message, user_id: u.id, post_id: post.id) end + + clear_possible_flags(topic) if post.post_number > 1 && topic.user_id != post.user_id end # Track the topic @@ -148,6 +150,25 @@ class PostCreator protected + def clear_possible_flags(topic) + # at this point we know the topic is a PM and has been replied to ... check if we need to clear any flags + # + first_post = Post.select(:id).where(topic_id: topic.id).where('post_number = 1').first + post_action = nil + + if first_post + post_action = PostAction.where( + related_post_id: first_post.id, + deleted_at: nil, + post_action_type_id: PostActionType.types[:notify_moderators] + ).first + end + + if post_action + post_action.remove_act!(@user) + end + end + def add_users(topic, usernames) return unless usernames usernames = usernames.split(',') diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index 3e74c3698..8183efc4c 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -24,7 +24,7 @@ describe PostAction do action = PostAction.act(codinghorror, post, PostActionType.types[:notify_moderators], "this is my special long message"); posts = Post.joins(:topic) - .select('posts.id, topics.subtype') + .select('posts.id, topics.subtype, posts.topic_id') .where('topics.archetype' => Archetype.private_message) .to_a @@ -32,6 +32,13 @@ describe PostAction do action.related_post_id.should == posts[0].id.to_i posts[0].subtype.should == TopicSubtype.notify_moderators + # reply to PM should 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 + + action.reload + action.deleted_at.should_not be_nil + end describe 'notify_moderators' do