mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 15:38:02 +08:00
FIX: user topic and post counts can become negative when staff deletes posts in personal messages
This commit is contained in:
@ -78,21 +78,23 @@ class PostDestroyer
|
||||
def staff_recovered
|
||||
@post.recover!
|
||||
|
||||
if author = @post.user
|
||||
if @post.is_first_post?
|
||||
author.user_stat.topic_count += 1
|
||||
else
|
||||
author.user_stat.post_count += 1
|
||||
if @post.topic && !@post.topic.private_message?
|
||||
if author = @post.user
|
||||
if @post.is_first_post?
|
||||
author.user_stat.topic_count += 1
|
||||
else
|
||||
author.user_stat.post_count += 1
|
||||
end
|
||||
author.user_stat.save!
|
||||
end
|
||||
author.user_stat.save!
|
||||
end
|
||||
|
||||
if @post.is_first_post? && @post.topic && !@post.topic.private_message?
|
||||
# Update stats of all people who replied
|
||||
counts = Post.where(post_type: Post.types[:regular], topic_id: @post.topic_id).where('post_number > 1').group(:user_id).count
|
||||
counts.each do |user_id, count|
|
||||
if user_stat = UserStat.where(user_id: user_id).first
|
||||
user_stat.update_attributes(post_count: user_stat.post_count + count)
|
||||
if @post.is_first_post?
|
||||
# Update stats of all people who replied
|
||||
counts = Post.where(post_type: Post.types[:regular], topic_id: @post.topic_id).where('post_number > 1').group(:user_id).count
|
||||
counts.each do |user_id, count|
|
||||
if user_stat = UserStat.where(user_id: user_id).first
|
||||
user_stat.update_attributes(post_count: user_stat.post_count + count)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -248,10 +250,12 @@ class PostDestroyer
|
||||
author.user_stat.first_post_created_at = author.posts.order('created_at ASC').first.try(:created_at)
|
||||
end
|
||||
|
||||
if @post.post_type == Post.types[:regular] && !@post.is_first_post? && !@topic.nil?
|
||||
author.user_stat.post_count -= 1
|
||||
if @post.topic && !@post.topic.private_message?
|
||||
if @post.post_type == Post.types[:regular] && !@post.is_first_post? && !@topic.nil?
|
||||
author.user_stat.post_count -= 1
|
||||
end
|
||||
author.user_stat.topic_count -= 1 if @post.is_first_post?
|
||||
end
|
||||
author.user_stat.topic_count -= 1 if @post.is_first_post?
|
||||
|
||||
# We don't count replies to your own topics in topic_reply_count
|
||||
if @topic && author.id != @topic.user_id
|
||||
|
Reference in New Issue
Block a user