FEATURE: Reset bump date when unhiding a post (#33926)

This is a continuation of #33895, implements automatic resetting of
topic bump date when a last reply is unhidden, so the topic will back to
the correct place it belongs on /latest based on its last public post.
This commit is contained in:
Linca
2025-07-30 10:31:02 +08:00
committed by GitHub
parent 0f78e29b1a
commit dd710bad2f
3 changed files with 45 additions and 5 deletions
+2
View File
@@ -706,6 +706,8 @@ class Post < ActiveRecord::Base
should_update_user_stat = false
end
self.topic.reset_bumped_at(self) if is_last_reply? && !whisper?
# We need to do this because TopicStatusUpdater also does the increment
# and we don't want to double count for the OP.
UserStatCountUpdater.increment!(self) if should_update_user_stat
+7 -5
View File
@@ -1922,11 +1922,13 @@ class Topic < ActiveRecord::Base
@is_category_topic ||= Category.exists?(topic_id: self.id.to_i)
end
def reset_bumped_at(post_id = nil)
def reset_bumped_at(post_or_post_id = nil)
post =
(
if post_id
Post.find_by(id: post_id)
if post_or_post_id.is_a?(Post)
post_or_post_id
else
if post_or_post_id
Post.find_by(id: post_or_post_id)
else
ordered_posts.where(
user_deleted: false,
@@ -1934,7 +1936,7 @@ class Topic < ActiveRecord::Base
post_type: Post.types[:regular],
).last || first_post
end
)
end
return if !post
+36
View File
@@ -1655,6 +1655,42 @@ RSpec.describe Post do
1,
)
end
context "in a topic with multiple replies" do
let!(:second_last_reply) do
freeze_time 1.day.from_now
create_post(topic:, user: coding_horror, hidden: true)
end
fab!(:user)
let!(:last_reply) do
freeze_time 2.days.from_now
create_post(topic:, user:, hidden: true)
end
let!(:whisper_post) do
freeze_time 3.days.from_now
create_post(topic:, user: user, post_type: Post.types[:whisper], hidden: true)
end
before { topic.update_columns(bumped_at: 1.day.from_now) }
it "does not reset the topic's bumped_at when unhiding a whisper" do
whisper_post.unhide!
expect(topic.reload.bumped_at).to eq_time(1.day.from_now)
end
it "resets the topic's bumped_at when unhiding the last visible reply" do
last_reply.unhide!
expect(topic.reload.bumped_at).to eq_time(last_reply.created_at)
end
it "does not reset the topic's bumped_at when unhiding a reply that is not the last" do
second_last_reply.unhide!
expect(topic.reload.bumped_at).to eq_time(1.day.from_now)
end
end
end
it "will unhide the post but will keep the topic invisible/unlisted" do