From f69356e62819179eaf54a90f619d7672b7eca65e Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 22 Jun 2018 11:32:45 +0800 Subject: [PATCH] FIX: Users can't "show all posts" in forced summary topics. --- .../javascripts/discourse/lib/transform-post.js.es6 | 6 ++++-- .../javascripts/discourse/models/post-stream.js.es6 | 2 ++ lib/topic_view.rb | 8 ++++++-- spec/components/topic_view_spec.rb | 7 +++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/transform-post.js.es6 b/app/assets/javascripts/discourse/lib/transform-post.js.es6 index 5602d0592b1..ac574a4a1ce 100644 --- a/app/assets/javascripts/discourse/lib/transform-post.js.es6 +++ b/app/assets/javascripts/discourse/lib/transform-post.js.es6 @@ -178,9 +178,11 @@ export default function transformPost( const postStream = topic.get("postStream"); postAtts.userFilters = postStream.userFilters; - postAtts.topicSummaryEnabled = - postStream.summary || topic.force_summary_mode; + if (topic.force_summary_mode) { + postStream.set('summary', topic.force_summary_mode); + } + postAtts.topicSummaryEnabled = postStream.summary; postAtts.topicWordCount = topic.word_count; postAtts.hasTopicSummary = topic.has_summary || topic.force_summary_mode; } diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6 index 7b4b27249ea..a22a6b9a660 100644 --- a/app/assets/javascripts/discourse/models/post-stream.js.es6 +++ b/app/assets/javascripts/discourse/models/post-stream.js.es6 @@ -108,6 +108,8 @@ export default RestModel.extend({ const result = {}; if (summary) { result.filter = "summary"; + } else { + result.filter = "none"; } const userFilters = this.get("userFilters"); diff --git a/lib/topic_view.rb b/lib/topic_view.rb index abe40a04aaf..90d55d04cbc 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -407,7 +407,9 @@ class TopicView def force_summary_mode? @force_summary_mode ||= - (@topic.closed? && @topic.posts_count >= (MEGA_TOPIC_POSTS_COUNT * 2)) + @filter != 'none' && + @topic.closed? && + @topic.posts_count >= (MEGA_TOPIC_POSTS_COUNT * 2) end protected @@ -487,7 +489,9 @@ class TopicView @filtered_posts = unfiltered_posts # Filters - if @filter == 'summary' || ((@post_number.blank? || @post_number.to_i == 1) && 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 diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb index b06b7210fe3..211933064d7 100644 --- a/spec/components/topic_view_spec.rb +++ b/spec/components/topic_view_spec.rb @@ -391,6 +391,13 @@ describe TopicView do expect(topic_view.contains_gaps?).to eq(false) expect(topic_view.posts).to eq([p1, p2, p3]) end + + it 'should not be forced into summary mode if filter is none' do + topic_view = TopicView.new(topic.id, evil_trout, filter: 'none') + + expect(topic_view.contains_gaps?).to eq(false) + expect(topic_view.posts).to eq([p1, p2, p3]) + end end it "#restricts to correct topic" do