Skip to content

A platform for community discussion. Free, open, simple.

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

Lincadd710bad2f55
diff --git a/app/models/post.rb b/app/models/post.rb
index 7b2f036ac89..7157cae2a22 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -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
diff --git a/app/models/topic.rb b/app/models/topic.rb
index 348f136bd6b..b541ed8f778 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -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
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index 6747125c383..329a4c7b81c 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -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