2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-08-17 18:04:11 +08:00

FEATURE: Reset bump date when deleting a post (#33747)

Necro-posting by spammers will bump the topic, and once you delete them,
those topics will still sit in `/latest` without any benifit.

This commit implements automatic resetting of topic bump date when a
post is deleted, so the topic will go to the correct place it belongs on
`/latest` based on its last public post.
This commit is contained in:
Linca 2025-07-24 14:03:33 +08:00 committed by GitHub
parent ae27128a9d
commit ebc5703b42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 50 additions and 0 deletions

View file

@ -554,6 +554,10 @@ class Post < ActiveRecord::Base
post_number.blank? ? topic.try(:highest_post_number) == 0 : post_number == 1
end
def is_last_reply?
topic.try(:highest_post_number) == post_number && post_number != 1
end
def is_category_description?
topic.present? && topic.is_category_topic? && is_first_post?
end

View file

@ -75,6 +75,8 @@ class PostDestroyer
delete_removed_posts_after =
@opts[:delete_removed_posts_after] || SiteSetting.delete_removed_posts_after
should_reset_bumped_at = @post.is_last_reply? && !@post.whisper?
if delete_removed_posts_after < 1 || post_is_reviewable? ||
Guardian.new(@user).can_moderate_topic?(@topic) || permanent?
perform_delete
@ -105,6 +107,8 @@ class PostDestroyer
Discourse.clear_urls!
end
end
@topic.reset_bumped_at if should_reset_bumped_at
end
def recover

View file

@ -1278,4 +1278,46 @@ RSpec.describe PostDestroyer do
end
end
end
describe "deleting a last reply" do
let!(:topic) { post.topic }
let!(:second_last_reply) do
freeze_time 1.day.from_now
create_post(topic:, user: coding_horror)
end
fab!(:user)
let!(:last_reply) do
freeze_time 2.days.from_now
create_post(topic:, user:)
end
context "when deleting by the creator" do
before { PostDestroyer.new(user, last_reply).destroy }
it "will reset the topic's bumped_at" do
topic.reload
expect(topic.bumped_at).to eq_time(second_last_reply.created_at)
end
it "still can see the post" do
last_reply.reload
expect(last_reply.deleted_at).to be_blank
expect(last_reply.deleted_by).to be_blank
expect(last_reply.user_deleted).to eq(true)
expect(last_reply.raw).to eq(I18n.t("js.post.deleted_by_author_simple"))
end
end
context "when deleting by a staff user" do
before { PostDestroyer.new(moderator, last_reply).destroy }
it "will reset the topic's bumped_at" do
topic.reload
expect(topic.bumped_at).to eq_time(second_last_reply.created_at)
end
end
end
end