Skip to content

FEATURE: Reset bump date when unhiding a post #33926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,8 @@ def unhide!
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
Expand Down
12 changes: 7 additions & 5 deletions app/models/topic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1922,19 +1922,21 @@ def is_category_topic?
@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,
hidden: false,
post_type: Post.types[:regular],
).last || first_post
end
)
end

return if !post

Expand Down
36 changes: 36 additions & 0 deletions spec/models/post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,42 @@ def post_with_body(body, user = nil)
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
Expand Down
Loading