2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-03-18 16:52:29 -05:00
|
|
|
#
|
|
|
|
# How a post is deleted is affected by who is performing the action.
|
|
|
|
# this class contains the logic to delete it.
|
|
|
|
#
|
|
|
|
class PostDestroyer
|
|
|
|
|
2014-09-25 12:51:00 -05:00
|
|
|
def self.destroy_old_hidden_posts
|
2015-12-29 15:59:26 -06:00
|
|
|
Post.where(deleted_at: nil, hidden: true)
|
2014-09-25 12:51:00 -05:00
|
|
|
.where("hidden_at < ?", 30.days.ago)
|
|
|
|
.find_each do |post|
|
|
|
|
PostDestroyer.new(Discourse.system_user, post).destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-22 02:48:24 -05:00
|
|
|
def self.destroy_stubs
|
2017-04-24 21:19:21 -05:00
|
|
|
context = I18n.t('remove_posts_deleted_by_author')
|
|
|
|
|
2013-07-23 01:11:44 -05:00
|
|
|
# exclude deleted topics and posts that are actively flagged
|
2013-07-22 02:48:24 -05:00
|
|
|
Post.where(deleted_at: nil, user_deleted: true)
|
2013-07-23 01:11:44 -05:00
|
|
|
.where("NOT EXISTS (
|
|
|
|
SELECT 1 FROM topics t
|
|
|
|
WHERE t.deleted_at IS NOT NULL AND
|
|
|
|
t.id = posts.topic_id
|
|
|
|
)")
|
2019-05-07 08:25:52 -05:00
|
|
|
.where("updated_at < ?", SiteSetting.delete_removed_posts_after.hours.ago)
|
2013-07-23 01:11:44 -05:00
|
|
|
.where("NOT EXISTS (
|
|
|
|
SELECT 1
|
|
|
|
FROM post_actions pa
|
2018-08-09 13:54:23 -05:00
|
|
|
WHERE pa.post_id = posts.id
|
|
|
|
AND pa.deleted_at IS NULL
|
|
|
|
AND pa.deferred_at IS NULL
|
|
|
|
AND pa.post_action_type_id IN (?)
|
2013-07-23 01:11:44 -05:00
|
|
|
)", PostActionType.notify_flag_type_ids)
|
2017-04-24 21:19:21 -05:00
|
|
|
.find_each do |post|
|
|
|
|
|
|
|
|
PostDestroyer.new(Discourse.system_user, post, context: context).destroy
|
2013-07-22 02:48:24 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-27 14:19:44 -06:00
|
|
|
def self.delete_with_replies(performed_by, post, reviewable = nil, defer_reply_flags: true)
|
2019-05-27 11:27:16 -05:00
|
|
|
reply_ids = post.reply_ids(Guardian.new(performed_by), only_replies_to_single_post: false)
|
|
|
|
replies = Post.where(id: reply_ids.map { |r| r[:id] })
|
2019-08-30 08:27:52 -05:00
|
|
|
PostDestroyer.new(performed_by, post, reviewable: reviewable).destroy
|
2019-11-27 14:19:44 -06:00
|
|
|
replies.each { |reply| PostDestroyer.new(performed_by, reply, defer_flags: defer_reply_flags).destroy }
|
2019-05-27 11:27:16 -05:00
|
|
|
end
|
|
|
|
|
2014-10-01 10:40:13 -05:00
|
|
|
def initialize(user, post, opts = {})
|
2014-08-07 12:12:35 -05:00
|
|
|
@user = user
|
|
|
|
@post = post
|
2014-08-14 14:21:10 -05:00
|
|
|
@topic = post.topic if post
|
2014-10-01 10:40:13 -05:00
|
|
|
@opts = opts
|
2013-03-18 16:52:29 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2019-02-19 00:53:42 -06:00
|
|
|
payload = WebHook.generate_payload(:post, @post) if WebHook.active_web_hooks(:post).exists?
|
2018-10-05 03:53:59 -05:00
|
|
|
topic = @post.topic
|
2019-12-04 14:13:31 -06:00
|
|
|
is_first_post = @post.is_first_post? && topic
|
2018-10-05 03:53:59 -05:00
|
|
|
|
2019-12-04 14:13:31 -06:00
|
|
|
if is_first_post
|
2018-10-05 03:53:59 -05:00
|
|
|
topic_view = TopicView.new(topic.id, Discourse.system_user)
|
2019-02-19 00:53:42 -06:00
|
|
|
topic_payload = WebHook.generate_payload(:topic, topic_view, WebHookTopicViewSerializer) if WebHook.active_web_hooks(:topic).exists?
|
2018-10-05 03:53:59 -05:00
|
|
|
end
|
|
|
|
|
2017-06-15 22:27:51 -05:00
|
|
|
delete_removed_posts_after = @opts[:delete_removed_posts_after] || SiteSetting.delete_removed_posts_after
|
|
|
|
|
|
|
|
if @user.staff? || delete_removed_posts_after < 1
|
2014-10-06 15:29:20 -05:00
|
|
|
perform_delete
|
2013-03-18 16:52:29 -05:00
|
|
|
elsif @user.id == @post.user_id
|
2017-06-15 22:27:51 -05:00
|
|
|
mark_for_deletion(delete_removed_posts_after)
|
2013-03-18 16:52:29 -05:00
|
|
|
end
|
2019-01-03 11:03:01 -06:00
|
|
|
|
|
|
|
UserActionManager.post_destroyed(@post)
|
|
|
|
|
2015-05-15 02:24:48 -05:00
|
|
|
DiscourseEvent.trigger(:post_destroyed, @post, @opts, @user)
|
2019-03-06 11:22:54 -06:00
|
|
|
WebHook.enqueue_post_hooks(:post_destroyed, @post, payload)
|
2016-09-05 06:00:49 -05:00
|
|
|
|
2019-12-04 14:13:31 -06:00
|
|
|
if is_first_post
|
2019-12-09 13:15:47 -06:00
|
|
|
UserProfile.remove_featured_topic_from_all_profiles(@topic)
|
2019-12-04 14:13:31 -06:00
|
|
|
UserActionManager.topic_destroyed(topic)
|
|
|
|
DiscourseEvent.trigger(:topic_destroyed, topic, @user)
|
|
|
|
WebHook.enqueue_topic_hooks(:topic_destroyed, topic, topic_payload)
|
2016-09-05 06:00:49 -05:00
|
|
|
end
|
2013-03-18 16:52:29 -05:00
|
|
|
end
|
|
|
|
|
2013-07-22 02:48:24 -05:00
|
|
|
def recover
|
|
|
|
if @user.staff? && @post.deleted_at
|
|
|
|
staff_recovered
|
|
|
|
elsif @user.staff? || @user.id == @post.user_id
|
|
|
|
user_recovered
|
|
|
|
end
|
2014-12-09 13:42:24 -06:00
|
|
|
topic = Topic.with_deleted.find @post.topic_id
|
2020-02-06 02:19:04 -06:00
|
|
|
topic.update_column(:user_id, Discourse::SYSTEM_USER_ID) if !topic.user_id
|
2019-01-03 11:03:01 -06:00
|
|
|
topic.recover!(@user) if @post.is_first_post?
|
2014-12-09 13:42:24 -06:00
|
|
|
topic.update_statistics
|
2019-01-03 11:03:01 -06:00
|
|
|
UserActionManager.post_created(@post)
|
2015-05-15 02:24:48 -05:00
|
|
|
DiscourseEvent.trigger(:post_recovered, @post, @opts, @user)
|
2018-03-20 23:15:16 -05:00
|
|
|
if @post.is_first_post?
|
2019-03-29 08:36:29 -05:00
|
|
|
UserActionManager.topic_created(topic)
|
2018-03-20 23:15:16 -05:00
|
|
|
DiscourseEvent.trigger(:topic_recovered, topic, @user)
|
|
|
|
StaffActionLogger.new(@user).log_topic_delete_recover(topic, "recover_topic", @opts.slice(:context)) if @user.id != @post.user_id
|
|
|
|
end
|
2013-07-22 02:48:24 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def staff_recovered
|
2020-02-06 02:19:04 -06:00
|
|
|
@post.update_column(:user_id, Discourse::SYSTEM_USER_ID) if !@post.user_id
|
2013-07-22 02:48:24 -05:00
|
|
|
@post.recover!
|
2016-06-12 22:25:06 -05:00
|
|
|
|
2019-03-28 01:28:01 -05:00
|
|
|
mark_topic_changed
|
|
|
|
|
2018-07-03 21:50:51 -05:00
|
|
|
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!
|
2017-11-09 17:05:53 -06:00
|
|
|
end
|
2016-06-12 22:25:06 -05:00
|
|
|
|
2018-07-03 21:50:51 -05:00
|
|
|
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
|
2019-04-29 02:32:25 -05:00
|
|
|
user_stat.update(post_count: user_stat.post_count + count)
|
2018-07-03 21:50:51 -05:00
|
|
|
end
|
2017-11-09 17:05:53 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-28 22:34:32 -05:00
|
|
|
@post.publish_change_to_clients! :recovered
|
2017-11-09 17:05:53 -06:00
|
|
|
TopicTrackingState.publish_recover(@post.topic) if @post.topic && @post.is_first_post?
|
2013-07-22 02:48:24 -05:00
|
|
|
end
|
|
|
|
|
2013-03-18 16:52:29 -05:00
|
|
|
# When a post is properly deleted. Well, it's still soft deleted, but it will no longer
|
|
|
|
# show up in the topic
|
2014-10-06 15:29:20 -05:00
|
|
|
def perform_delete
|
2013-03-18 16:52:29 -05:00
|
|
|
Post.transaction do
|
2014-02-06 06:54:34 -06:00
|
|
|
@post.trash!(@user)
|
2013-07-23 10:50:58 -05:00
|
|
|
if @post.topic
|
2014-02-06 06:54:34 -06:00
|
|
|
make_previous_post_the_last_one
|
2019-03-28 01:28:01 -05:00
|
|
|
mark_topic_changed
|
2014-02-06 06:54:34 -06:00
|
|
|
clear_user_posted_flag
|
|
|
|
Topic.reset_highest(@post.topic_id)
|
2013-07-09 14:20:18 -05:00
|
|
|
end
|
2014-07-28 12:17:37 -05:00
|
|
|
trash_public_post_actions
|
2014-06-04 10:41:11 -05:00
|
|
|
trash_user_actions
|
2014-02-06 06:54:34 -06:00
|
|
|
remove_associated_replies
|
|
|
|
remove_associated_notifications
|
2015-04-23 12:33:29 -05:00
|
|
|
if @post.topic && @post.is_first_post?
|
2018-03-20 23:15:16 -05:00
|
|
|
StaffActionLogger.new(@user).log_topic_delete_recover(@post.topic, "delete_topic", @opts.slice(:context)) if @user.id != @post.user_id
|
2014-10-01 10:40:13 -05:00
|
|
|
@post.topic.trash!(@user)
|
2014-10-06 15:29:20 -05:00
|
|
|
elsif @user.id != @post.user_id
|
2014-10-01 10:40:13 -05:00
|
|
|
StaffActionLogger.new(@user).log_post_deletion(@post, @opts.slice(:context))
|
|
|
|
end
|
2014-02-06 06:54:34 -06:00
|
|
|
update_associated_category_latest_topic
|
2014-08-14 14:21:10 -05:00
|
|
|
update_user_counts
|
2015-06-17 18:58:32 -05:00
|
|
|
TopicUser.update_post_action_cache(post_id: @post.id)
|
2019-01-03 11:03:01 -06:00
|
|
|
|
2018-11-21 20:25:19 -06:00
|
|
|
DB.after_commit do
|
2019-08-30 08:27:52 -05:00
|
|
|
if @opts[:reviewable]
|
|
|
|
notify_deletion(@opts[:reviewable])
|
|
|
|
elsif reviewable = @post.reviewable_flag
|
|
|
|
@opts[:defer_flags] ? ignore(reviewable) : agree(reviewable)
|
2018-11-29 11:14:18 -06:00
|
|
|
end
|
2018-11-21 20:25:19 -06:00
|
|
|
end
|
2013-03-18 16:52:29 -05:00
|
|
|
end
|
2014-06-03 23:10:34 -05:00
|
|
|
|
2015-04-06 02:27:05 -05:00
|
|
|
feature_users_in_the_topic if @post.topic
|
2014-08-28 22:34:32 -05:00
|
|
|
@post.publish_change_to_clients! :deleted if @post.topic
|
2016-03-29 19:17:52 -05:00
|
|
|
TopicTrackingState.publish_delete(@post.topic) if @post.topic && @post.post_number == 1
|
2013-03-18 16:52:29 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# When a user 'deletes' their own post. We just change the text.
|
2017-06-15 22:27:51 -05:00
|
|
|
def mark_for_deletion(delete_removed_posts_after = SiteSetting.delete_removed_posts_after)
|
2015-01-24 20:19:57 -06:00
|
|
|
I18n.with_locale(SiteSetting.default_locale) do
|
2016-06-22 02:28:46 -05:00
|
|
|
|
|
|
|
# don't call revise from within transaction, high risk of deadlock
|
2019-03-29 11:10:05 -05:00
|
|
|
key = @post.is_first_post? ? 'js.topic.deleted_by_author' : 'js.post.deleted_by_author'
|
2017-06-15 22:27:51 -05:00
|
|
|
@post.revise(@user,
|
2019-03-29 11:10:05 -05:00
|
|
|
{ raw: I18n.t(key, count: delete_removed_posts_after) },
|
2019-06-20 10:23:49 -05:00
|
|
|
force_new_version: true,
|
|
|
|
deleting_post: true
|
2017-06-15 22:27:51 -05:00
|
|
|
)
|
2016-06-22 02:28:46 -05:00
|
|
|
|
2015-01-24 20:19:57 -06:00
|
|
|
Post.transaction do
|
|
|
|
@post.update_column(:user_deleted, true)
|
|
|
|
@post.topic_links.each(&:destroy)
|
2019-05-07 08:25:52 -05:00
|
|
|
@post.topic.update_column(:closed, true) if @post.is_first_post?
|
2015-01-24 20:19:57 -06:00
|
|
|
end
|
2013-03-18 16:52:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-22 02:48:24 -05:00
|
|
|
def user_recovered
|
2019-04-11 15:21:00 -05:00
|
|
|
return unless @post.user_deleted?
|
|
|
|
|
2013-07-22 02:48:24 -05:00
|
|
|
Post.transaction do
|
|
|
|
@post.update_column(:user_deleted, false)
|
2013-09-06 10:50:05 -05:00
|
|
|
@post.skip_unique_check = true
|
2019-05-07 08:25:52 -05:00
|
|
|
@post.topic.update_column(:closed, false) if @post.is_first_post?
|
2013-07-22 02:48:24 -05:00
|
|
|
end
|
2016-06-22 02:28:46 -05:00
|
|
|
|
|
|
|
# has internal transactions, if we nest then there are some very high risk deadlocks
|
2018-09-21 03:34:45 -05:00
|
|
|
last_revision = @post.revisions.last
|
2019-04-10 12:10:21 -05:00
|
|
|
if last_revision.present? && last_revision.modifications['raw'].present?
|
|
|
|
@post.revise(@user, { raw: last_revision.modifications["raw"][0] }, force_new_version: true)
|
|
|
|
end
|
2013-07-22 02:48:24 -05:00
|
|
|
end
|
|
|
|
|
2014-02-06 06:54:34 -06:00
|
|
|
private
|
|
|
|
|
2019-03-28 01:28:01 -05:00
|
|
|
# we need topics to change if ever a post in them is deleted or created
|
|
|
|
# this ensures users relying on this information can keep unread tracking
|
|
|
|
# working as desired
|
|
|
|
def mark_topic_changed
|
|
|
|
# make this as fast as possible, can bypass everything
|
|
|
|
DB.exec(<<~SQL, updated_at: Time.now, id: @post.topic_id)
|
|
|
|
UPDATE topics
|
|
|
|
SET updated_at = :updated_at
|
|
|
|
WHERE id = :id
|
|
|
|
SQL
|
|
|
|
end
|
|
|
|
|
2014-02-06 06:54:34 -06:00
|
|
|
def make_previous_post_the_last_one
|
2019-03-28 01:28:01 -05:00
|
|
|
last_post = Post
|
|
|
|
.select(:created_at, :user_id, :post_number)
|
|
|
|
.where("topic_id = ? and id <> ?", @post.topic_id, @post.id)
|
|
|
|
.order('created_at desc')
|
|
|
|
.limit(1)
|
|
|
|
.first
|
|
|
|
|
2018-07-13 11:15:59 -05:00
|
|
|
if last_post.present? && @post.topic.present?
|
|
|
|
topic = @post.topic
|
|
|
|
topic.last_posted_at = last_post.created_at
|
|
|
|
topic.last_post_user_id = last_post.user_id
|
|
|
|
topic.highest_post_number = last_post.post_number
|
2019-03-28 01:28:01 -05:00
|
|
|
|
|
|
|
# we go via save here cause we need to run hooks
|
2018-07-13 11:15:59 -05:00
|
|
|
topic.save!(validate: false)
|
2014-02-06 06:54:34 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def clear_user_posted_flag
|
|
|
|
unless Post.exists?(["topic_id = ? and user_id = ? and id <> ?", @post.topic_id, @post.user_id, @post.id])
|
|
|
|
TopicUser.where(topic_id: @post.topic_id, user_id: @post.user_id).update_all 'posted = false'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def feature_users_in_the_topic
|
2015-04-06 02:27:05 -05:00
|
|
|
Jobs.enqueue(:feature_topic_users, topic_id: @post.topic_id)
|
2014-02-06 06:54:34 -06:00
|
|
|
end
|
|
|
|
|
2014-07-28 12:17:37 -05:00
|
|
|
def trash_public_post_actions
|
2018-10-02 10:25:08 -05:00
|
|
|
if public_post_actions = PostAction.publics.where(post_id: @post.id)
|
|
|
|
public_post_actions.each { |pa| pa.trash!(@user) }
|
2014-02-06 06:54:34 -06:00
|
|
|
|
2018-10-02 10:25:08 -05:00
|
|
|
@post.custom_fields["deleted_public_actions"] = public_post_actions.ids
|
|
|
|
@post.save_custom_fields
|
|
|
|
|
|
|
|
f = PostActionType.public_types.map { |k, _| ["#{k}_count", 0] }
|
|
|
|
Post.with_deleted.where(id: @post.id).update_all(Hash[*f.flatten])
|
|
|
|
end
|
2014-02-06 06:54:34 -06:00
|
|
|
end
|
|
|
|
|
2019-01-03 11:03:01 -06:00
|
|
|
def agree(reviewable)
|
2019-08-30 08:27:52 -05:00
|
|
|
notify_deletion(reviewable)
|
2019-01-03 11:03:01 -06:00
|
|
|
result = reviewable.perform(@user, :agree_and_keep, post_was_deleted: true)
|
|
|
|
reviewable.transition_to(result.transition_to, @user)
|
2018-11-26 09:58:37 -06:00
|
|
|
end
|
|
|
|
|
2019-01-03 11:03:01 -06:00
|
|
|
def ignore(reviewable)
|
|
|
|
reviewable.perform_ignore(@user, post_was_deleted: true)
|
|
|
|
reviewable.transition_to(:ignored, @user)
|
2018-11-29 11:14:18 -06:00
|
|
|
end
|
|
|
|
|
2019-08-30 08:27:52 -05:00
|
|
|
def notify_deletion(reviewable)
|
2020-03-11 07:03:20 -05:00
|
|
|
return if @post.user.blank?
|
|
|
|
|
2019-08-30 08:27:52 -05:00
|
|
|
allowed_user = @user.human? && @user.staff?
|
|
|
|
return unless allowed_user && rs = reviewable.reviewable_scores.order('created_at DESC').first
|
|
|
|
|
|
|
|
Jobs.enqueue(
|
|
|
|
:send_system_message,
|
|
|
|
user_id: @post.user_id,
|
|
|
|
message_type: :flags_agreed_and_post_deleted,
|
|
|
|
message_options: {
|
|
|
|
flagged_post_raw_content: @post.raw,
|
|
|
|
url: @post.url,
|
|
|
|
flag_reason: I18n.t(
|
|
|
|
"flag_reasons.#{PostActionType.types[rs.reviewable_score_type]}",
|
|
|
|
locale: SiteSetting.default_locale,
|
|
|
|
base_path: Discourse.base_path
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2014-06-04 10:41:11 -05:00
|
|
|
def trash_user_actions
|
|
|
|
UserAction.where(target_post_id: @post.id).each do |ua|
|
|
|
|
row = {
|
|
|
|
action_type: ua.action_type,
|
|
|
|
user_id: ua.user_id,
|
|
|
|
acting_user_id: ua.acting_user_id,
|
|
|
|
target_topic_id: ua.target_topic_id,
|
|
|
|
target_post_id: ua.target_post_id
|
|
|
|
}
|
|
|
|
UserAction.remove_action!(row)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-06 06:54:34 -06:00
|
|
|
def remove_associated_replies
|
2020-01-17 10:24:49 -06:00
|
|
|
post_ids = PostReply.where(reply_post_id: @post.id).pluck(:post_id)
|
2014-02-06 06:54:34 -06:00
|
|
|
|
|
|
|
if post_ids.present?
|
2020-01-17 10:24:49 -06:00
|
|
|
PostReply.where(reply_post_id: @post.id).delete_all
|
2014-02-06 06:54:34 -06:00
|
|
|
Post.where(id: post_ids).each { |p| p.update_column :reply_count, p.replies.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_associated_notifications
|
2017-08-30 23:06:56 -05:00
|
|
|
Notification
|
|
|
|
.where(topic_id: @post.topic_id, post_number: @post.post_number)
|
|
|
|
.delete_all
|
2014-02-06 06:54:34 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def update_associated_category_latest_topic
|
|
|
|
return unless @post.topic && @post.topic.category
|
2015-04-23 12:33:29 -05:00
|
|
|
return unless @post.id == @post.topic.category.latest_post_id || (@post.is_first_post? && @post.topic_id == @post.topic.category.latest_topic_id)
|
2014-02-06 06:54:34 -06:00
|
|
|
|
|
|
|
@post.topic.category.update_latest
|
|
|
|
end
|
|
|
|
|
2014-08-14 14:21:10 -05:00
|
|
|
def update_user_counts
|
|
|
|
author = @post.user
|
|
|
|
|
|
|
|
return unless author
|
|
|
|
|
|
|
|
author.create_user_stat if author.user_stat.nil?
|
|
|
|
|
|
|
|
if @post.created_at == author.user_stat.first_post_created_at
|
|
|
|
author.user_stat.first_post_created_at = author.posts.order('created_at ASC').first.try(:created_at)
|
|
|
|
end
|
|
|
|
|
2018-07-03 21:50:51 -05:00
|
|
|
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?
|
2017-11-02 15:43:09 -05:00
|
|
|
end
|
2014-08-14 14:21:10 -05:00
|
|
|
|
|
|
|
author.user_stat.save!
|
|
|
|
|
|
|
|
if @post.created_at == author.last_posted_at
|
|
|
|
author.last_posted_at = author.posts.order('created_at DESC').first.try(:created_at)
|
|
|
|
author.save!
|
|
|
|
end
|
2017-11-02 14:33:40 -05:00
|
|
|
|
|
|
|
if @post.is_first_post? && @post.topic && !@post.topic.private_message?
|
|
|
|
# Update stats of all people who replied
|
2017-11-09 17:05:53 -06:00
|
|
|
counts = Post.where(post_type: Post.types[:regular], topic_id: @post.topic_id).where('post_number > 1').group(:user_id).count
|
2017-11-02 14:33:40 -05:00
|
|
|
counts.each do |user_id, count|
|
|
|
|
if user_stat = UserStat.where(user_id: user_id).first
|
2019-04-29 02:32:25 -05:00
|
|
|
user_stat.update(post_count: user_stat.post_count - count)
|
2017-11-02 14:33:40 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-08-14 14:21:10 -05:00
|
|
|
end
|
|
|
|
|
2013-05-03 02:56:23 -05:00
|
|
|
end
|