Skip to content

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

FEATURE: Reset bump date when hiding a post (#33895)

Linca7a320a4b7469
diff --git a/app/models/post.rb b/app/models/post.rb
index 76fca38a52e..7b2f036ac89 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -629,6 +629,7 @@ class Post < ActiveRecord::Base
)
hiding_again = hidden_at.present?
+ should_reset_bumped_at = is_last_reply? && !whisper?
Post.transaction do
self.skip_validation = true
@@ -679,6 +680,8 @@ class Post < ActiveRecord::Base
message_options: options,
)
end
+
+ topic.reset_bumped_at if should_reset_bumped_at
end
def unhide!
diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb
index 31c3383d552..6747125c383 100644
--- a/spec/models/post_spec.rb
+++ b/spec/models/post_spec.rb
@@ -1559,6 +1559,42 @@ RSpec.describe Post do
t.reload
expect(t.visible).to eq(false)
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)
+ end
+ fab!(:user)
+ let!(:last_reply) do
+ freeze_time 2.days.from_now
+ create_post(topic:, user:)
+ end
+ let!(:whisper_post) do
+ freeze_time 3.days.from_now
+ create_post(topic:, user: user, post_type: Post.types[:whisper])
+ end
+
+ before { topic.update_columns(bumped_at: 1.day.from_now) }
+
+ it "does not reset the topic's bumped_at when hiding a whisper" do
+ whisper_post.hide!(PostActionType.types[:off_topic])
+
+ expect(topic.reload.bumped_at).to eq_time(1.day.from_now)
+ end
+
+ it "resets the topic's bumped_at when hiding the last visible reply" do
+ last_reply.hide!(PostActionType.types[:off_topic])
+
+ expect(topic.reload.bumped_at).to eq_time(second_last_reply.created_at)
+ end
+
+ it "does not reset the topic's bumped_at when hiding a reply that is not the last" do
+ second_last_reply.hide!(PostActionType.types[:off_topic])
+
+ expect(topic.reload.bumped_at).to eq_time(1.day.from_now)
+ end
+ end
end
describe "#unhide!" do