diff --git a/app/assets/javascripts/discourse/lib/transform-post.js.es6 b/app/assets/javascripts/discourse/lib/transform-post.js.es6 index 80106ecc0b3..31d5fdb0dd1 100644 --- a/app/assets/javascripts/discourse/lib/transform-post.js.es6 +++ b/app/assets/javascripts/discourse/lib/transform-post.js.es6 @@ -177,9 +177,9 @@ export default function transformPost( const postStream = topic.get("postStream"); postAtts.userFilters = postStream.userFilters; - postAtts.topicSummaryEnabled = postStream.summary; + postAtts.topicSummaryEnabled = postStream.summary || topic.force_summary_mode; postAtts.topicWordCount = topic.word_count; - postAtts.hasTopicSummary = topic.has_summary; + postAtts.hasTopicSummary = topic.has_summary || topic.force_summary_mode; } if (postAtts.isDeleted) { diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rb index 9475da548a1..5044aa6177d 100644 --- a/app/serializers/topic_view_serializer.rb +++ b/app/serializers/topic_view_serializer.rb @@ -68,6 +68,7 @@ class TopicViewSerializer < ApplicationSerializer :participant_count, :destination_category_id, :pm_with_non_human_user, + :force_summary_mode, # TODO: Split off into proper object / serializer def details @@ -299,6 +300,10 @@ class TopicViewSerializer < ApplicationSerializer object.topic.shared_draft.present? end + def force_summary_mode + object.force_summary_mode? + end + private def private_message?(topic) diff --git a/lib/topic_view.rb b/lib/topic_view.rb index d180db56820..abe40a04aaf 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -405,6 +405,11 @@ class TopicView end end + def force_summary_mode? + @force_summary_mode ||= + (@topic.closed? && @topic.posts_count >= (MEGA_TOPIC_POSTS_COUNT * 2)) + end + protected def read_posts_set @@ -482,7 +487,7 @@ class TopicView @filtered_posts = unfiltered_posts # Filters - if @filter == 'summary' || force_summary_mode? + if @filter == 'summary' || ((@post_number.blank? || @post_number.to_i == 1) && force_summary_mode?) @filtered_posts = @filtered_posts.summary(@topic.id) @contains_gaps = true unless force_summary_mode? end @@ -572,9 +577,4 @@ class TopicView def is_mega_topic? @topic.posts_count >= MEGA_TOPIC_POSTS_COUNT end - - def force_summary_mode? - @force_summary_mode ||= - (@topic.closed? && @topic.posts_count >= (MEGA_TOPIC_POSTS_COUNT * 2)) - end end diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb index 241649187b2..b06b7210fe3 100644 --- a/spec/components/topic_view_spec.rb +++ b/spec/components/topic_view_spec.rb @@ -365,22 +365,31 @@ describe TopicView do end describe 'when a megalodon topic is closed' do + before do + @original_const = TopicView::MEGA_TOPIC_POSTS_COUNT + TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT") + TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", 1) + topic.update!(closed: true) + SiteSetting.summary_max_results = 2 + end + + after do + TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT") + TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", @original_const) + end + it 'should be forced into summary mode without gaps' do - begin - original_const = TopicView::MEGA_TOPIC_POSTS_COUNT - TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT") - TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", 1) - SiteSetting.summary_max_results = 2 - topic.update!(closed: true) + topic_view = TopicView.new(topic.id, evil_trout, post_number: 1) - topic_view = TopicView.new(topic.id, evil_trout) + expect(topic_view.contains_gaps?).to eq(false) + expect(topic_view.posts).to eq([p5]) + end - expect(topic_view.contains_gaps?).to eq(false) - expect(topic_view.posts).to eq([p5]) - ensure - TopicView.send(:remove_const, "MEGA_TOPIC_POSTS_COUNT") - TopicView.const_set("MEGA_TOPIC_POSTS_COUNT", original_const) - end + it 'should not be forced into summary mode if post_number is not blank' do + topic_view = TopicView.new(topic.id, evil_trout, post_number: 2) + + expect(topic_view.contains_gaps?).to eq(false) + expect(topic_view.posts).to eq([p1, p2, p3]) end end