A platform for community discussion. Free, open, simple.
Force summary mode when user enters at the top of megalodoon topics.
Guo Xiang Tan9a7a079f4dbc
diff --git a/app/assets/javascripts/discourse/lib/transform-post.js.es6 b/app/assets/javascripts/discourse/lib/transform-post.js.es6index 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.rbindex 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 / serializerdef details@@ -299,6 +300,10 @@ class TopicViewSerializer < ApplicationSerializerobject.topic.shared_draft.present?end+ def force_summary_mode+ object.force_summary_mode?+ end+privatedef private_message?(topic)diff --git a/lib/topic_view.rb b/lib/topic_view.rbindex d180db56820..abe40a04aaf 100644--- a/lib/topic_view.rb+++ b/lib/topic_view.rb@@ -405,6 +405,11 @@ class TopicViewendend+ def force_summary_mode?+ @force_summary_mode ||=+ (@topic.closed? && @topic.posts_count >= (MEGA_TOPIC_POSTS_COUNT * 2))+ end+protecteddef 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 TopicViewdef is_mega_topic?@topic.posts_count >= MEGA_TOPIC_POSTS_COUNTend-- def force_summary_mode?- @force_summary_mode ||=- (@topic.closed? && @topic.posts_count >= (MEGA_TOPIC_POSTS_COUNT * 2))- endenddiff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rbindex 241649187b2..b06b7210fe3 100644--- a/spec/components/topic_view_spec.rb+++ b/spec/components/topic_view_spec.rb@@ -365,22 +365,31 @@ describe TopicView doenddescribe '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])endend