clear flags on reply to notify moderators
This commit is contained in:
parent
a27046bacd
commit
9b33e826f2
|
@ -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
|
||||
|
|
|
@ -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(',')
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue